- Messages
- 1,682
- Reaction score
- 32
- Points
- 48
I have been looking around the internet when I first started making these, and I really never could find a good one that was easy for the beginner.
I am not going to go into big detail here since it would be a lot to cover, but I'll go over the basics.
--------------------------------------------------------------------
we start with the variable that we are going to call this image, lets say
from there we can either call in another picture that we will superimpose onto, or make a new one
For colors GD does not allow us to use Hexadecimal values, so we have to convert them to RGB, http://www.kenjikojima.com/java/RGBHexConverter2.html
I like to place my colors in a variable so it is easier to reference than placing imagecolorallocate($image, 255, 255, 255); for white
for the font, I also like to refer to them as a variable, but make sure you have the correct directory, otherwise it doesn't work
now for the fun part, adding in text
we will use the imagettftext fuction, the syntax is as follows:
now after all that is settled, we need to tell the browser to display this as a png, rather than php; or any other picture file
hope it is easier for you guys to understand
libraryofmike is the best one that I have found so far, it gets to the basic, so you can progress from there.Here are a few good ones I have found:
http://libraryofmike.org/php/creating-images-with-php-and-gd/
http://www.papaface.com/blog/2008/01/06/how-to-make-a-dynamic-image/
And of course if you are gonna use PHP, why not ask the makers of it : http://us2.php.net/image
I am not going to go into big detail here since it would be a lot to cover, but I'll go over the basics.
--------------------------------------------------------------------
we start with the variable that we are going to call this image, lets say
PHP:
$image
PHP:
//New One
$image = imagecreatetruecolor(200, 200);
//(w x h)
//Call in another picture
$image = imagecreatefrompng("picture.png");
//imagecreatefrompng, can be switch to jpg, gif, and some other check PHP.NET for others
I like to place my colors in a variable so it is easier to reference than placing imagecolorallocate($image, 255, 255, 255); for white
PHP:
$white = imagecolorallocate($image, 255, 255, 255);
PHP:
$font = 'yourfont.ttf';
we will use the imagettftext fuction, the syntax is as follows:
PHP:
imagettftext(image, size, angle, x, y, color, font, "text");
//image - the image you are to draw on
//size - the size of the text (points)
//angle - what angle you would like the text to display at
//x - x-coordinate
//y - y-coordinate
//color - the color you would like the text to be (this case $white)
//font - the font you would like the text to be (this case $font)
//text - the text you would like to display
PHP:
header("Content-type: image/png");
//tells the browser it is a png picture
imagepng($image);
//displays the png image "image"
imagedestroy($image);
//removes the image from memory
hope it is easier for you guys to understand