PHP | imagepng() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 $quality, int $filters) Parameters: This function accepts three parameters as mentioned above and described below: $image: It specifies the image resource to work on. $to (Optional): It specifies the path to save the file to. $quality (Optional): It specifies the quality of the image. $filters (Optional): It specifies the filters to apply to the image which help in reducing the image size. Return Value: This function returns TRUE on success or FALSE on error. Below examples illustrate the imagepng() function in PHP: Example 1: In this example we will be viewing an image in browser. php <?php // Load an image from PNG URL $im = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // View the loaded image in browser using imagepng() function header('Content-type: image/png'); imagepng($im); imagedestroy($im); ?> Output: Example 2: IN this example we will convert JPEG into PNG. php <?php // Load an image from JPEG URL $im = imagecreatefromjpeg( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Convert the image into PNG using imagepng() function imagepng($im, 'converted.png'); imagedestroy($im); ?> Output: This will save the PNG version of image in the same folder where your PHP script is. Program 3: In this example we will use filters. php <?php // Create an image instance $im = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Save the image as image1.png imagepng($im, 'image1.png'); // Save the image as image2.png with all filters to disable size compression imagepng($im, 'image2.png', null, PNG_ALL_FILTERS); imagedestroy($im); ?> Output: This will save the image1.png as compressed and image2.png as uncompressed image Reference: https://www.php.net/manual/en/function.imagepng.php Comment More infoAdvertise with us Next Article PHP | imagepng() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads 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 | 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 | 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 | 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 | imagebmp() Function The imagebmp() function is an inbuilt function in PHP which is used to return the output or save a BMP version of the given image. Syntax: bool imagebmp( resource $image, mixed $to, bool $compressed ) Parameters: This function accept three parameters as mentioned above and described below: $image: I 1 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 | 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 | imagesx() Function The imagesx() function is an inbuilt function in PHP which is used to return the width of the given image. Syntax: int imagesx( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable can store the image created by imagecreatetruecolor() image cre 1 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 PHP | imagewbmp() Function The imagewbmp() 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 imagewbmp( resource $image, int $to, int $foreground ) Parameters: This fu 2 min read Like