1
0
Fork 0
mirror of synced 2024-07-03 05:31:38 +12:00

Using native PHP webp for image output

This commit is contained in:
Eldad Fux 2020-07-03 12:12:26 +03:00
parent fb71414dc3
commit 26e3b22f76

View file

@ -131,35 +131,35 @@ class Resize
break; break;
case 'webp': case 'webp':
//$this->image->setImageFormat('webp'); $this->image->setImageFormat('webp');
$signature = $this->image->getImageSignature(); // $signature = $this->image->getImageSignature();
$temp = '/tmp/temp-'.$signature.'.'.\strtolower($this->image->getImageFormat()); // $temp = '/tmp/temp-'.$signature.'.'.\strtolower($this->image->getImageFormat());
$output = '/tmp/output-'.$signature.'.webp'; // $output = '/tmp/output-'.$signature.'.webp';
// save temp // // save temp
$this->image->writeImages($temp, true); // $this->image->writeImages($temp, true);
// convert temp // // convert temp
\exec("cwebp -quiet -metadata none -q $quality $temp -o $output"); // \exec("cwebp -quiet -metadata none -q $quality $temp -o $output");
$data = \file_get_contents($output); // $data = \file_get_contents($output);
//load webp // //load webp
if (empty($path)) { // if (empty($path)) {
return $data; // return $data;
} else { // } else {
\file_put_contents($path, $data, LOCK_EX); // \file_put_contents($path, $data, LOCK_EX);
} // }
$this->image->clear(); // $this->image->clear();
$this->image->destroy(); // $this->image->destroy();
//delete webp // //delete webp
\unlink($output); // \unlink($output);
\unlink($temp); // \unlink($temp);
return; // return;
break; break;