PHP | imagegd2() Function
Last Updated :
29 Jan, 2020
The imagegd2() function is an inbuilt function in PHP which is used to output GD2 image to browser or file. This is most useful to convert any other image type to gd2. The imagecreatefromgd2() function can be used to further read gd2 images.
Syntax:
bool imagegd2( resource $image, float $to,
int $chunk_size, int $type )
Parameters: This function accepts four parameters as mentioned above and described below:
- $image: It specifies the image to be worked upon.
- $to (Optional): It specifies the path to save the file to.
- $chunk_size (Optional): It specifies the size of chunk.
- $type (Optional): It specifies the type of compression to use which can be one of IMG_GD2_RAW or IMG_GD2_COMPRESSED.
Return Value: This function returns TRUE on success or FALSE on failure.
Exceptions: This function throws Exception on error.
Below examples illustrate the imagegd2() function in PHP:
Example 1: Viewing a GD2 file.
<?php
$im = imagecreatetruecolor(200, 200);
$text_color = imagecolorallocate( $im , 233, 14, 91);
imagestring( $im , 0, 30, 30, "GeeksforGeeks" , $text_color );
imagegd2( $im );
?>
|
Output:
This will output the image in the form of string
as gd2 isn't supported in browser.
Example 2: Convert images into GD2.
<?php
$im = imagecreatefrompng(
imagegd2( $im , 'geeksforgeeks.gd2' );
?>
|
Output:
This will save a image with name geeksforgeeks.gd2 in the same folder.
Reference: https://www.php.net/manual/en/function.imagegd2.php
Share your thoughts in the comments
Please Login to comment...