PHP | imagewebp() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report 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 $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 imagewebp() function in PHP:Example 1: In this example we will be viewing an image in browser. php <?php // Load an image from local webp file // Images can be converted into webp // using imagewebp() function or other // online convertors $im = imagecreatefromwebp('./geeksforgeeks.webp'); // View the loaded image in browser // using imagewebp() function header('Content-type: image/webp'); imagewebp($im); imagedestroy($im); ?> Output: Example 2: In this example we will convert PNG into WEBP. php <?php // Load an image from local webp file // Images can be converted into webp // using imagewebp() function or other // online convertors $im = imagecreatefromwebp('./geeksforgeeks.webp'); // Convert the image into webp // using imagewebp() function imagewebp($im, 'converted.webp'); imagedestroy($im); ?> Output: This will save the WEBP version of image in the same folder where your PHP script is. Program 3: In this example we will alter the image quality. php <?php // Load an image from local webp file // Images can be converted into webp // using imagewebp() function or other // online convertors $im = imagecreatefromwebp('./geeksforgeeks.webp'); // Convert the image into webp using imagewebp() // function and view in the browser header('Content-type: image/webp'); imagewebp($im, null, 0); imagedestroy($im); ?> Output: Reference: https://www.php.net/manual/en/function.imagewebp.php Comment More infoAdvertise with us Next Article PHP | imagewebp() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-image-functions Similar Reads 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 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 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 Like