PHP Imagecreate( ) FunctionImage create ( ) function is another inbuilt PHP function mainly used to create a new image. The function returns the given image in a specific size. We need to define the width and height of the required image. Instead of the image create ( ) function, we can also use other creative functions like imagecreatetruecolor( ), which is a better alternative as it will return a better image quality. Syntax In PHP, imagecreate( ) function follows the following syntax.
The image creates ( ) function returns the resource identifier of an image on successful execution of the program and FALSE on a failed attempt. Examples of Imagecreate( ) FunctionExample 1: PHP program to display the basic use of imagecreate( ) function Output The above code shows the following Output. Here in this program, we have declared various variables like $image to define the size of the image that we require, $background color to define the color of background we require, $text color to define the color of text we require. We have used the image string ( ) function to declare the string we want to display as an image. To display the output of the image, we have used an inbuilt PHP command header and imagepng to display on the browser. Example 2: PHP program to display the use of imagecreate( ) function Output This PHP code gives the following output. Here in this program, we have declared various variables like $image to define the size of the image that we require, $background color to define the color of background we require, $text color to define the color of text we require. We have used the image string ( ) function to declare the string we want to display as an image. To display the output of the image, we have used an inbuilt PHP command header and imagepng to display on the browser. Example 3: PHP program to display the use of imagecreate( ) function to draw a polygon. Output The above code draws the polygon as an output. Here in this program, we have declared various variables like $image to define the size of the image that we require, $background color to define the color of background we require, $text color to define the color of text we require, an array $values to set the coordinates of the polygon we need to declare, and we have used image polygon ( ) function to display the polygon we want to display as an image, to display the output of the image we have used an inbuilt PHP command header and imagepng to display on browser. Next Topic# |