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,8 +398,6 @@ 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();
if($this->imWebp->readImage($dstFilename)) {
// prepare for webp output // prepare for webp output
$this->imWebp->setImageFormat('webp'); $this->imWebp->setImageFormat('webp');
$this->imWebp->setImageCompressionQuality($this->webpQuality); $this->imWebp->setImageCompressionQuality($this->webpQuality);
@@ -404,7 +406,6 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
// save to file // save to file
$return = $this->imWebp->writeImage($webpFilename); $return = $this->imWebp->writeImage($webpFilename);
} }
}
// release and return to event-object // release and return to event-object
$this->release(); $this->release();