function yttags_jpg2webp($src_file_path, $file_destination_path, $compression_qty = 100) { $image = imagecreatefromjpeg($src_file_path); $final_output = imagewebp($image, $file_destination_path, $compression_qty); if (false === $final_output) { return false; } imagedestroy($image); return $file_destination_path; }
Function usage:
echo yttags_jpg2webp('img/oldfile.jpg','img/newfile.webp',100);