Javatpoint Logo
Javatpoint Logo

PHP Imagecreate( ) Function

Image 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.


S.No Parameter Description Optional / mandatory
1 $ width This parameter is used to define the image's width that we want to display. Mandatory
2 $ height This parameter is used to define the height of the image that we want to display Mandatory

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( ) Function

Example 1: PHP program to display the basic use of imagecreate( ) function

Output

The above code shows the following Output.

PHP Imagecreate( ) Function

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.

PHP Imagecreate( ) Function

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.

PHP Imagecreate( ) Function

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#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA