Create Image Using php

Today I just came up with a php tutorial for creating images with the php extensions
Firstly you should check the php_gd2 library extension is enabled... 
this library provides some function to create the images in php( this must be enabled to make work the below code)
The below code will give the output an image with the hello world text with black background.
 $string="Hello World";// Text that will display in the image
 $len=strlen($string)*10;// based on the text length it will automatically adjusts the width
 $image = imagecreate($len,40);//width and height of the image
 $background = imagecolorallocate($image,0,0,0);//background color of the image
 $color = imagecolorallocate($image,255,255,226);//foreground of the color( only rgb values are allowed in this function)
 imagestring($image, 10,10,1,$string,$color);//adding string to the image and their parameters(image,fontsize,x,y,string, font color)
 header("Content-type: image/jpeg");// This must be important to display image(jpeg) for png replace jpeg with png
 imagejpeg($image);// for png image use imagepng($image)
I think the comment line will explain the code
If its difficult to follow, let me know your thoughts

Working For Cause Not For Applause

Tagged with: , , , ,
Posted in PHP

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: