PHP | imagecreatefromgd2() function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The imagecreatefromgd2() function is an inbuilt function in PHP which is used to create a new image from 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 imagecreatefromgd2( string $filename ) Parameters: This function accepts a single parameter $filename which holds the name or URL of file.Return Value: This function returns an image resource identifier on success, FALSE on errors.Below given programs illustrate the imagecreatefromgd2() function in PHP:Program 1 (Viewing a gd2 file in browser): php <?php // Load the GD2 image from local folder // GD2 images can be created with imagegd2() function $im = imagecreatefromgd2('geeksforgeeks.gd2'); // Convert to PNG and output to the browser header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?> Output: Program 2 (Converting gd2 into jpeg): php <?php // Load the GD2 image $im = imagecreatefromgd2('geeksforgeeks.gd2'); // Convert it to a JPEG file, press Ctrl + S to save the new jpeg image header('Content-type: image/jpeg'); imagejpeg($im); imagedestroy($im); ?> Output: Reference: https://www.php.net/manual/en/function.imagecreatefromgd2.php Comment More infoAdvertise with us Next Article PHP | imagecreatefromgd2() function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads PHP | imagecreatefromgd() function The imagecreatefromgd() function is an inbuilt function in PHP which is used to create a new image from GD file or URL. Further, this image can be worked upon in the program. An image can be converted into GD format using the imagegd() function. Syntax: resource imagecreatefromgd( string $filename ) 2 min read 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 v 2 min read PHP | imagecreatefrompng() Function The imagecreatefrompng() function is an inbuilt function in PHP which is used to create a new image from PNG file or URL. This image can be further worked upon in the program. This function is usually used when you want to edit your PNG images. Syntax: resource imagecreatefrompng( string $filename ) 1 min read PHP | imagecreatefromgif() Function The imagecreatefromgif() function is an inbuilt function in PHP which is used to create a new image from a given part of GIF file or URL. Further, this image can be worked upon in the program. This function only loads the first frame of the animation. Syntax: resource imagecreatefromgif( string $fil 1 min read PHP | imagecreatefromjpeg() Function The imagecreatefromjpeg() function is an inbuilt function in PHP which is used to create a new image from JPEG file or URL. This image can be further worked upon in the program. Syntax: resource imagecreatefromjpeg( string $filename ) Parameters: This function accepts a single parameter, $filename w 1 min read PHP | imagecreatefrombmp() Function The imagecreatefrombmp() function is an inbuilt function in PHP which is used to create a new image from file or URL. Syntax: resource imagecreatefrombmp( string $filename ) Parameters: This function accepts a single parameter $filename which holds the name or URL of a file. Return Value: This funct 1 min read PHP | imagecreatefromxbm() function The imagecreatefromxbm() function is an inbuilt function in PHP which is used to create a new image from XBM file or URL. XBM file extension is an X Bitmap Graphics file used for Graphical UI systems. This loaded image can be further worked upon in the program. This function is usually used when you 2 min read PHP | imagecreatefromxpm() Function The imagecreatefromxpm() function is an inbuilt function in PHP which is used to create a new image from XPM file or URL. XPM (X PixMap) is an image file format used by the X Window System. This loaded image can be further worked upon in the program. This function is usually used when you want to ed 2 min read PHP | imagecreatefromstring() Function The imagecreatefromstring() function is an inbuilt function in PHP which is used to create a new image from string file or URL. This image can be further worked upon in the program. This function is usually used when you want to edit your images after loading them from a string. Syntax: resource ima 2 min read PHP | imagecreatefromwebp() function The imagecreatefromwebp() function is an inbuilt function in PHP which is used to create a new image from WEBP file or URL. WEBP is an image format employing both lossy and lossless compression. This image can be further worked upon in the program. This function is usually used when you want to edit 2 min read Like