SearchSearch   MemberlistMembers   RegisterRegister   ProfileProfile   Log inLog in 

How To Write Text Over Images Using ASPJpeg

 
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> Articles and Tutorials -> Server Side Web Development
View previous topic :: View next topic  
Author Message
Nick
Forum Moderator


Joined: 18 Jun 2002
Posts: 3635

PostPosted: Sun Feb 26, 2006 7:35 pm    Post subject: How To Write Text Over Images Using ASPJpeg Reply with quote

How To Write Text Over Images Using ASPJpeg

The latest version of ASPJpeg allows us to write text over the top of images. Excellent for buttons or copyright notices.

With ASPJpeg you can easily manipulate images on the server. To call an image, we can do so by linking to an ASP file, passing the image path to the file.

Code:
<img src="changeImage.asp?path=d:\Webs\mydomain.co.uk\wwwroot\car.jpg">


The page "changeImage.asp" opens the image and sends it back to the browser. To write text over images, you can use the following method. This is the contents of changeImage.asp.

Code:
<%
Dim strText
strText = "© MySite.com"
'Set the text you want written over the image

Dim Jpeg
'Declare you're going to be using Jpeg

Set Jpeg = Server.CreateObject("Persits.Jpeg")
'Open ASPJpeg object

Jpeg.Open Request("path")
'Opens image as a new image in the server memory ready to edit

jpeg.Width = jpeg.OriginalWidth
'Sets width to actual image width

jpeg.Height = jpeg.OriginalHeight
'Sets width to actual image width

TextVertical = Jpeg.Height - 21
'A bit of trickery to get text to be printed
'21 pixels from the bottom of the new image

'Set first line of text as black, Arial, bold and size 14
Jpeg.Canvas.Font.Color = &H000000
Jpeg.Canvas.Font.Family = "Arial"
Jpeg.Canvas.Font.Bold = True
Jpeg.Canvas.Font.Size = 14

Jpeg.Canvas.Print 11, TextVertical + 1, strText
'Write text 11px from left edge

'Set second line of text as white, Arial, bold and size 14
Jpeg.Canvas.Font.Color = &HFFFFFF
Jpeg.Canvas.Font.Family = "Arial"
Jpeg.Canvas.Font.Bold = True
Jpeg.Canvas.Font.Size = 14

Jpeg.Canvas.Print 10, TextVertical, strText
'Write text 10px from left edge

Jpeg.SendBinary
'Send image to user's browser

Jpeg.Close
Set Jpeg = Nothing
'Be kind to the server and clear up!
%>


The only slightly tricky bit in the code above is the Jpeg.Canvas.Print which writes the text over your photo. It can contain 3 values, as in the example above - horizonal space, vertical space, and content. You'll notice in the example that the vertical (third value) isn't a number. Instead the variable "TextVertical" is asigned the value of the image height, minus 21. This is just for nice presentation, so the text is printed 21 pixels from the bottom of the image (the shadow being 21 and the normal text 20).
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Mark Voss
Divine Being


Joined: 19 Jun 2002
Posts: 4946
Location: Cardiff, UK

PostPosted: Sun Feb 26, 2006 8:55 pm    Post subject: Reply with quote

As an alternative, instead of writing a second line of text to get the drop-shadow effect, you could utilise some additional properties of the ASPJpeg Font object:

Code:
Jpeg.Canvas.Font.ShadowColor = &HFFFFFF
Jpeg.Canvas.Font.ShadowXoffset = -1
Jpeg.Canvas.Font.ShadowYoffset = 1
Back to top
View user's profile Send private message Visit poster's website
Nick
Forum Moderator


Joined: 18 Jun 2002
Posts: 3635

PostPosted: Wed Mar 08, 2006 2:42 pm    Post subject: Reply with quote

Cheers, Mark. I wasn't aware that Persits had added the Shadow property.
_________________
Nick Dunn
Nick Dunn
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> Articles and Tutorials -> Server Side Web Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.11 © 2001, 2002 phpBB Group
FAQClick here for help using the phpBB forum