• Log in or sign up for an account here: https://www.sythe.org/login

Dynamic Sigs for Dummies

tazrockon

Member

Banned
Joined
Apr 23, 2005
Sythe Gold
0
Messages
56
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.

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/
 
nice tutorial =)
 
verify and explain cause ur banned......... im not risking it lol
 
Extreme Homosex
Homosex
verify and explain cause ur banned......... im not risking it lol
He's banned due to infractions, not for making this guide. And as you can see in the code there's nothing malicious... Jeez
 
Nice guide, helped me and my friend a lot :D
 
very basic yet very helpful, thank you.
 
lol made simple hell its copy and past
 
.

All you're doing is adding text o.O
 
even thogh im a freaking geainus about computers,i dont get this
 
Too basic, not a very good tut.
Because it doesn't explain how you can't use php scripts within image tags of most forum. You'll have to rename the script to .jpg (or w/e) and set the server to run it as a php script... or there are a couple other methods, but this one is the easiest imo.

Then you could still have the filetype in the base name to adhere to the forum sig restrictions. Like this:

http://cruels.net/sigs/progress/Some stupid title.../Some stupid label.../74.png

74.png


EDIT: Oh... source and crap here: http://cruels.net/index.php?showtopic=4096
 
So like this :D
74.png


Anyone got an actual tut for dynamic sigs that explains more in-depth?
 
Runescape Gamblingrunescape gambling
Back
Top