mirror of
https://github.com/processwire/processwire.git
synced 2025-08-25 23:56:41 +02:00
rearranged code for webP saving
This commit is contained in:
@@ -359,11 +359,7 @@ 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;
|
|
||||||
}
|
|
||||||
$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'))) {
|
||||||
@@ -377,8 +373,8 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
|
|||||||
$this->im->setImageCompressionQuality($this->quality);
|
$this->im->setImageCompressionQuality($this->quality);
|
||||||
}
|
}
|
||||||
|
|
||||||
// write to file(s)
|
// write to file
|
||||||
$this->wire('files')->unlink($dstFilename);
|
if(file_exists($dstFilename)) $this->wire('files')->unlink($dstFilename);
|
||||||
@clearstatcache(dirname($dstFilename));
|
@clearstatcache(dirname($dstFilename));
|
||||||
##if(!$this->im->writeImage($this->destFilename)) {
|
##if(!$this->im->writeImage($this->destFilename)) {
|
||||||
// We use this approach for saving so that it behaves the same like core ImageSizer with images that
|
// 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();
|
$this->release();
|
||||||
return false;
|
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
|
// optionally create a WebP dependency file
|
||||||
if($this->webpAdd) {
|
if($this->webpAdd) {
|
||||||
$path_parts = pathinfo($dstFilename);
|
$this->imWebp = new \IMagick();
|
||||||
$webpFilename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.webp';
|
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);
|
||||||
#$this->imWebp->setOption('webp:method', '6');
|
$this->imWebp->setOption('webp:method', '6');
|
||||||
#$this->imWebp->setOption('webp:lossless', 'true');
|
#$this->imWebp->setOption('webp:lossless', 'true');
|
||||||
// save to file
|
// save to file
|
||||||
$this->wire('files')->unlink($webpFilename);
|
$return = $this->imWebp->writeImage($webpFilename);
|
||||||
@clearstatcache(dirname($webpFilename));
|
|
||||||
if(!file_put_contents($webpFilename, $this->imWebp)) {
|
|
||||||
$this->release();
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// release and return to event-object
|
// release and return to event-object
|
||||||
$this->release();
|
$this->release();
|
||||||
$this->modified = true;
|
return $return;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user