PHP | imagejpeg() Function Last Updated : 30 Jan, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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, int $quality ) 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. Return Value: This function returns TRUE on success or FALSE on error. Below examples illustrate the imagejpeg() function in PHP: Example 1: In this example we will be viewing an image in browser. php <?php // Load an image from jpeg URL $im = imagecreatefromjpeg( 'https://media.geeksforgeeks.org/wp-content/uploads/20200123100652/geeksforgeeks12.jpg'); // View the loaded image in browser using imagejpeg() function header('Content-type: image/jpg'); imagejpeg($im); imagedestroy($im); ?> Output: Example 2: In this example we will convert PNG into JPEG. php <?php // Load an image from PNG URL $im = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Convert the image into JPEG using imagejpeg() function imagejpeg($im, 'converted.jpg'); imagedestroy($im); ?> Output: This will save the JPEG version of image in the same folder where your PHP script is. Example 3: In this example we will alter the quality of the image. php <?php // Load an image from jpeg URL $im = imagecreatefromjpeg( 'https://media.geeksforgeeks.org/wp-content/uploads/20200123100652/geeksforgeeks12.jpg'); // View the loaded image in browser using imagejpeg() function header('Content-type: image/jpg'); // Decrease the quality of image to 2 imagejpeg($im, null, 2); imagedestroy($im); ?> Output: Reference: https://www.php.net/manual/en/function.imagejpeg.php Comment More infoAdvertise with us Next Article PHP | imagejpeg() Function G gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-Imagick Similar Reads 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 | 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 | 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