PHP | imagecreatefromgd2part() Function
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.
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):
Program 2 (Converting gd2 into jpeg):
It will load the part of image and convert it into JPEG and saves it into same folder.