ServicesRapid Web DevelopmentAudits & ModernizationAI StrategyDigital Growth & SEO
MenuThe LabProductsInsightsProfile
Contact
PHPUpdated: Jan 7, 2023

PHP function to convert a jpg image to webp

Speed up your website loading and improve SEO by converting your jpg images 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);
?>

Need this implemented in your infrastructure?

Hire Me to Deploy