Heya,
It is going to be pretty basic tutorial. I am gonna write the advanced or the other ones in the next tutorials. Here is a simple code in php which creates a image on the fly. This code is so simple,but i have written comment before each line to help you understand the flow of the code.
//creates a image handle $img = imagecreate( 200, 200 ); //choose a bg color, u can play with the rgb values $background = imagecolorallocate( $img,232, 0, 135 ); //chooses the text color $text_colour = imagecolorallocate( $img, 255, 255, 255 ); //sets the thickness/bolness of the line imagesetthickness ( $img, 3 ); //draws a line params are (imgres,x1,y1,x2,y2,color) imageline( $img, 20, 130, 165, 130, $text_colour ); //pulls the value passed in the URL $text = $_GET['days']; // place the font file in the same dir level as the php file $font = 'comic.ttf'; //this function sets the font size, places to the co-ords imagettftext($img, 100, 0, 11, 120, $text_colour, $font, $text); //places another text with smaller size imagettftext($img, 16, 0, 10, 160, $text_colour, $font, 'Small Text'); //alerts the browser abt the type of content i.e. png image header( 'Content-type: image/png' ); //now creates the image imagepng( $img ); //destroys used resources imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy( $img );
Any problems running the code, leave a comment. A working copy can be checked by visiting this url
http://www.digimantra.com/demo/image.php?days=69
Feel free to change the value of the days param to see the dynamic image creation.
Hope this helps
Cheers!!
Realin !



Hi
I tried to use the Script and i works pretty well, thanks.
But then I tried to use special characters (German: ä, ü, ö etc). That doesn’t work…
Can you help me with this issue? That would be great =)
Thanks, Simon
Currently the characters being printed are taken from URL in the demo script, you can use proper character coding to make it happen.
Thanks for your very fast answer! =)
Well, I tried to just enter ‘ä ö ü’ in the imagettftext() but that doesn’t work…
My font is an OTF that definitely has those special chars.
Have you got an idea how to fix this?
Thanks, Simon
Me again. I now used the same Font but as TTF – and it works. I read before on a website that TTF works better than OTF in imagettftext().
Thanks for your help, I appreciate that.
Regards from Switzerland
Simon
Cool !!
hi mine is dead
sorry have I missed a step I tried just pasting the code in between some php tags you can look at
http://www.hull-college.ac.uk/modr.php?days=69
if you can just give us some point of where i have gone wrong cheers
Hi Patrick,
Can you pastebin your code ? I can have a look at it.
was litterly a copy paste job from yours
http://pastebin.com/KuBPs0JR