1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-20 21:42:23 +02:00

refactored webp creation and compression

This commit is contained in:
horst-n
2019-04-26 18:11:04 +02:00
parent 023a672e26
commit 04135462c8

View File

@@ -360,6 +360,10 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
$this->im->setImageDepth(($this->imageDepth > 8 ? 8 : $this->imageDepth)); $this->im->setImageDepth(($this->imageDepth > 8 ? 8 : $this->imageDepth));
// prepare to save file(s) // prepare to save file(s)
if($this->webpAdd) {
$this->imWebp = clone $this->im; // make a copy before compressions take effect
}
$this->im->setImageFormat($this->imageFormat); $this->im->setImageFormat($this->imageFormat);
$this->im->setImageType($this->imageType); $this->im->setImageType($this->imageType);
if(in_array(strtoupper($this->imageFormat), array('JPG', 'JPEG'))) { if(in_array(strtoupper($this->imageFormat), array('JPG', 'JPEG'))) {
@@ -394,16 +398,13 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
// optionally create a WebP dependency file // optionally create a WebP dependency file
if($this->webpAdd) { if($this->webpAdd) {
$this->imWebp = new \IMagick(); // prepare for webp output
if($this->imWebp->readImage($dstFilename)) { $this->imWebp->setImageFormat('webp');
// prepare for webp output $this->imWebp->setImageCompressionQuality($this->webpQuality);
$this->imWebp->setImageFormat('webp'); $this->imWebp->setOption('webp:method', '6');
$this->imWebp->setImageCompressionQuality($this->webpQuality); #$this->imWebp->setOption('webp:lossless', 'true');
$this->imWebp->setOption('webp:method', '6'); // save to file
#$this->imWebp->setOption('webp:lossless', 'true'); $return = $this->imWebp->writeImage($webpFilename);
// save to file
$return = $this->imWebp->writeImage($webpFilename);
}
} }
// release and return to event-object // release and return to event-object