PHP | imagegd() function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The imagegd() function is an inbuilt function in PHP which is used to output GD image to browser or file. This is most useful to convert any other image type to gd. imagecreatefromgd() function can be used to further read gd images. Syntax: bool imagegd( resource $image, float $to) Parameters:This function accepts two 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. Return Value: This function returns TRUE on success or FALSE on failure. Exceptions: This function throws Exception on error. Below given programs illustrate the imagegd() function in PHP: Program 1 (Viewing a GD file): php <?php // Create a blank image and add text $im = imagecreatetruecolor(100, 100); $text_color = imagecolorallocate($im, 10, 10, 51); imagestring($im, 0, 20, 20, "GeeksforGeeks", $text_color); // Output the image as string imagegd($im); ?> Output: This will output the image in the form of string as gd isn't supported in browser. Program 2 (Convert images into gd): php <?php // Create a image from png $image = imagecreatefrompng('https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Convert into GD and save to the same folder imagegd($image, 'geeksforgeeks.gd'); ?> Output: This will save a image with name geeksforgeeks.gd in the same folder. Reference: https://www.php.net/manual/en/function.imagegd.php Comment More infoAdvertise with us Next Article PHP | imagegd() function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads PHP | imagegd2() Function 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 $ch 2 min read PHP | imagepng() Function The imagepng() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to PNG and applying filters to the image. Syntax: bool imagepng( resource $image, int $to, int $qual 2 min read PHP | imagegif() Function The imagegif() function is an inbuilt function in PHP which is used to create the GIF image file from the given image. If the image has been made transparent with imagecolortransparent() function, then GIF89a image format will generate otherwise GIF87a image format will generate. Syntax: bool imageg 2 min read PHP | imagejpeg() Function The imagejpeg() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to JPEG and altering the quality of the image. Syntax: bool imagejpeg( resource $image, int $to, in 2 min read PHP | imagesy() Function The imagesy() function is an inbuilt function in PHP which is used to return the height of the given image. Syntax: int imagesy( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable store the image created by imagecreatetruecolor() image creati 1 min read PHP | imagexbm() Function The imagexbm() function is an inbuilt function in PHP which is used to display image to browser a file. The main use of this function is to view an image in the browser and convert any other image type to XBM. Syntax: bool imagexbm( resource $image, int $to, int $foreground) Parameters: This functio 2 min read PHP | imagechar() Function The imagechar() function is an inbuilt function in PHP which is used to draw a character horizontally. This function draws the first character of string in the image identified by image with its x and y-axis. The coordinate of the top-left corner is (0, 0). Syntax: bool imagechar( $image, $font, $x, 2 min read PHP | imagewebp() Function The imagewebp() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to WebP and alter the quality of the image.Syntax:Â bool imagewebp( resource $image, int $to, int $q 2 min read PHP | imagestring() Function The imagestring() function is an inbuilt function in PHP which is used to draw the string horizontally. This function draws the string at given position. Syntax: bool imagestring( $image, $font, $x, $y, $string, $color ) Parameters: This function accepts six parameters as mentioned above and describ 2 min read PHP | imagecrop() Function The imagecrop() function is an inbuilt function in PHP which is used to crop an image to the given rectangle. This function crops an image to the given rectangular area and returns the resulting image. The given image is not modified. Syntax: resource imagecrop ( $image, $rect ) Parameters: This fun 1 min read Like