Here's an example of how to use php to write text on an image. When combined with PHP query strings, this can be used to create truly dynamic sigs that user's could change simply by changing the URL of the image.
Here's a code example I'll reference in this article. Note that ALL # SIGNS NEED TO BE CHANGED TO $ SIGNS TO MAKE THE SCRIPT WORK. The forum was messing up the code displayed when I used $ signs in the example.
Part 1:
The header is used to define the image type. In this case it's .jpg.
Part 2:
The ImageCreateFromJpeg function loads an image file from your server, in this case background.jpg. This is the image you want to write on.
Part 3:
The ImageColorAllocate function is setting the color of the text you want to write. It's in RGB color format, which in this example is 0, 0, 0 which is black.
Part 4:
The ImageTTFText function physically writes the text on the image. Here's what all the attributes are for this function:
imagettftext(resource image, font size, font angle, x-pos, y-pos, color, fontfile, text)
It's important to note that for this function to work properly you need to upload the fontfile you want to use to your server. You can just grab a font like Arial off your computer or find one you like more on the internet. It needs to be uploaded to the same directory as this script. In this example I used arialbd.ttf (arial bold). In the example the font size is 16, then angle is 0 (font's in a straight line), the (x, y) coordinates of where the first letter of the text is being written on the background image is (85, 154). You can get these by loading the background image you want to use in Microsoft Paint, putting your mouse over the spot where you want the text to begin, and looking at the coordinates Paint gives you in the bottom right corner of the program. In the color section of the function we used $txt_color to reference the color we set in Part 3. The final part of the function is the text you want to write. In the example we are writing Mary-Jane Juana. This all may seem a bit complicated but it's really not.
Part 5:
ImageJpeg displays the new image you just created.
If you have any questions, ask Google. These sites go in depth into how to use a lot more features of the PHP GD Library (what we used to write the textP:
http://www.phpit.net/article/image-manipulation-php-gd-part1/
http://www.phpit.net/article/image-manipulation-php-gd-part2/
http://www.codewalkers.com/c/a/Miscellaneous/Overlapping-Images-with-GD/
Here's a code example I'll reference in this article. Note that ALL # SIGNS NEED TO BE CHANGED TO $ SIGNS TO MAKE THE SCRIPT WORK. The forum was messing up the code displayed when I used $ signs in the example.
Code:
<?php
//Part 1:
header ("Content-type: image/jpg");
//Part 2:
#handle = ImageCreateFromJpeg("background.jpg");
//Part 3:
#txt_color = ImageColorAllocate (#handle, 0, 0, 0);
//Part 4:
ImageTTFText (#handle, 16, 0, 85, 154, #txt_color, "arialbd.ttf", "Mary-Jane Juana");
//Part 5:
ImageJpeg (#handle);
?>
Part 1:
The header is used to define the image type. In this case it's .jpg.
Part 2:
The ImageCreateFromJpeg function loads an image file from your server, in this case background.jpg. This is the image you want to write on.
Part 3:
The ImageColorAllocate function is setting the color of the text you want to write. It's in RGB color format, which in this example is 0, 0, 0 which is black.
Part 4:
The ImageTTFText function physically writes the text on the image. Here's what all the attributes are for this function:
imagettftext(resource image, font size, font angle, x-pos, y-pos, color, fontfile, text)
It's important to note that for this function to work properly you need to upload the fontfile you want to use to your server. You can just grab a font like Arial off your computer or find one you like more on the internet. It needs to be uploaded to the same directory as this script. In this example I used arialbd.ttf (arial bold). In the example the font size is 16, then angle is 0 (font's in a straight line), the (x, y) coordinates of where the first letter of the text is being written on the background image is (85, 154). You can get these by loading the background image you want to use in Microsoft Paint, putting your mouse over the spot where you want the text to begin, and looking at the coordinates Paint gives you in the bottom right corner of the program. In the color section of the function we used $txt_color to reference the color we set in Part 3. The final part of the function is the text you want to write. In the example we are writing Mary-Jane Juana. This all may seem a bit complicated but it's really not.
Part 5:
ImageJpeg displays the new image you just created.
If you have any questions, ask Google. These sites go in depth into how to use a lot more features of the PHP GD Library (what we used to write the textP:
http://www.phpit.net/article/image-manipulation-php-gd-part1/
http://www.phpit.net/article/image-manipulation-php-gd-part2/
http://www.codewalkers.com/c/a/Miscellaneous/Overlapping-Images-with-GD/







