PHP | imagecreatefromgd2part() Function
Last Updated :
14 Feb, 2020
The imagecreatefromgd2part() function is an inbuilt function in PHP which is used to create a new image from a given part of GD2 file or URL. Further, this image can be worked upon in the program. Usually, gd2 extension is not supported in the browser thus it can be used to convert it into png and view it in the browser.
Syntax:
resource imagecreatefromgdpart( string $filename,
int $srcX, int $srcY, int $width, int $height )
Parameters: This function accept five parameters as mentioned above and described below:
- $filename: It specifies the GD2 image.
- $srcX: It specifies the x-coordinate of source point.
- $srcY: It specifies the y-coordinate of source point.
- $width: It specifies the width of image.
- $height: It specifies the height of image.
Return Value: This function returns an image resource identifier on success, FALSE on errors.
Below given programs illustrate the imagecreatefromgd2part() function in PHP:
Program 1 (Viewing a gd2 file in browser):
<?php
$im = imagecreatefromgd2part( './geeksforgeeks.gd2' ,
300, 0, 300, 300);
header( 'Content-type: image/png' );
imagepng( $im );
imagedestroy( $im );
?>
|
Output:
Program 2 (Converting gd2 into jpeg):
<?php
$im = imagecreatefromgd2part( './geeksforgeeks.gd2' ,
30, 0, 100, 250);
imagejpeg( $im , 'newgeeksforgeeks.jpeg' );
imagedestroy( $im );
?>
|
Output:
It will load the part of image and convert it
into JPEG and saves it into same folder.
Reference: https://www.php.net/manual/en/function.imagecreatefromgd2part.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...