
PHP function to convert a jpg image to webp
Navigation
- Home ⟶ Programming Examples ⟶ PHP Examples ⟶ PHP function to convert a jpg image to webp
Please check the example below
<?php
$image= imagecreatefromjpeg($str_file_name);
ob_start();
imagejpeg($image,NULL,100);
$cont= ob_get_contents();
ob_end_clean();
imagedestroy($image);
$content = imagecreatefromstring($cont);
imagewebp($content,str_replace(".jpg",".webp",$str_file_name));
echo "Converted: ".$str_file_name." to: ".str_replace(".jpg",".webp",$str_file_name)."
";
imagedestroy($content);
?>
Discover more PHP Examples & Tutorials
PHP examples and tutorials
Example of searching XML file with PHP and XPath
Sanitizing the user input with the PHP filter_var function
May 4,2023