PHP | imagegd2() Function Last Updated : 29 Jan, 2020 Comments Improve Suggest changes Like Article Like Report 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 <?php // Create a blank image and add text $im = imagecreatetruecolor(200, 200); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 0, 30, 30, "GeeksforGeeks", $text_color); // Output the image as string 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 <?php // Create a image from png $im = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Convert into GD2 and save to the same folder 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 Comment More infoAdvertise with us Next Article PHP | imagegd2() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function Similar Reads PHP | imagegd() function 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 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 | image2wbmp() function The image2wbmp() 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 and convert any other image type to WBMP.Syntax:  bool image2wbmp( resource $image, int $filename, int $foreground) Parameters: 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 | imagecopy() Function The imagecopy() function is an inbuilt function in PHP which is used to copy the image or part of image. This function returns true on success or false on failure. Syntax: bool imagecopy ( $dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h ) Parameters: This function accepts eigh 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 | imageflip() Function The imageflip() function is an inbuilt function in PHP which is used to Flip an image horizontally, vertically or both horizontally and vertically using the given mode. Syntax: bool imageflip( $image, $mode ) Parameters: This function accepts two parameters as mentioned above and described below: $i 2 min read Like