1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-24 15:23:11 +02:00

rearranged code for webP saving

This commit is contained in:
horst-n
2019-04-25 11:01:13 +02:00
parent 4e534e0315
commit 35b9a403e1

View File

@@ -359,11 +359,7 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
$this->im->setImageDepth(($this->imageDepth > 8 ? 8 : $this->imageDepth));
// prepare to save file(s)
if($this->webpAdd) {
$this->imWebp = clone $this->im;
}
$this->im->setImageFormat($this->imageFormat);
$this->im->setImageType($this->imageType);
if(in_array(strtoupper($this->imageFormat), array('JPG', 'JPEG'))) {
@@ -377,8 +373,8 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
$this->im->setImageCompressionQuality($this->quality);
}
// write to file(s)
$this->wire('files')->unlink($dstFilename);
// write to file
if(file_exists($dstFilename)) $this->wire('files')->unlink($dstFilename);
@clearstatcache(dirname($dstFilename));
##if(!$this->im->writeImage($this->destFilename)) {
// We use this approach for saving so that it behaves the same like core ImageSizer with images that
@@ -388,28 +384,31 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
$this->release();
return false;
}
// set modified flag and delete optional webp dependency file
$this->modified = true;
$return = true;
$path_parts = pathinfo($srcFilename);
$webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp';
if(file_exists($webpFilename)) $this->wire('files')->unlink($webpFilename);
// optionally create a WebP dependency file
if($this->webpAdd) {
$path_parts = pathinfo($dstFilename);
$webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp';
// prepare for webp output
$this->imWebp->setImageFormat('webp');
$this->imWebp->setImageCompressionQuality($this->webpQuality);
#$this->imWebp->setOption('webp:method', '6');
#$this->imWebp->setOption('webp:lossless', 'true');
// save to file
$this->wire('files')->unlink($webpFilename);
@clearstatcache(dirname($webpFilename));
if(!file_put_contents($webpFilename, $this->imWebp)) {
$this->release();
return false;
$this->imWebp = new \IMagick();
if($this->imWebp->readImage($dstFilename)) {
// prepare for webp output
$this->imWebp->setImageFormat('webp');
$this->imWebp->setImageCompressionQuality($this->webpQuality);
$this->imWebp->setOption('webp:method', '6');
#$this->imWebp->setOption('webp:lossless', 'true');
// save to file
$return = $this->imWebp->writeImage($webpFilename);
}
}
// release and return to event-object
$this->release();
$this->modified = true;
return true;
return $return;
}
/**