PHP function to convert a jpg image to webp

Speed up your website loading and improve SEO by converting your jpg images to webp ...

Home Programming Examples PHP Examples → PHP function to convert a jpg image to webp
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);
?>




See More PHP ExamplesHire Me For A Project






 
Connect with meLinkedIn ProfileFacebook Profile


2024 © SofiaCoder.com
×

Programming ExamplesPHP ExamplesMySQL ExamplesJavaScript ExamplesHTML ExamplesCSS ExamplesNode.js ExamplesOther Home PageSofia Coder LinkedIn ProfileSofia Coder Facebook Profile