mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 15:23:11 +02:00
Add @horst-n PR #118 which fixes processwire/processwire-issues#628 in ImageSizerEngine
This commit is contained in:
@@ -669,28 +669,28 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable
|
|||||||
if($targetWidth == $originalTargetWidth && 1 + $targetWidth == $pWidth) $pWidth = $pWidth - 1;
|
if($targetWidth == $originalTargetWidth && 1 + $targetWidth == $pWidth) $pWidth = $pWidth - 1;
|
||||||
if($targetHeight == $originalTargetHeight && 1 + $targetHeight == $pHeight) $pHeight = $pHeight - 1;
|
if($targetHeight == $originalTargetHeight && 1 + $targetHeight == $pHeight) $pHeight = $pHeight - 1;
|
||||||
|
|
||||||
if(!$this->upscaling) {
|
if(!$this->upscaling && ($img['width'] < $targetWidth || $img['height'] < $targetHeight)) {
|
||||||
// we are going to shoot for something smaller than the target
|
// via @horst-n PR #118:
|
||||||
|
// upscaling is not allowed and we have one or both dimensions to small,
|
||||||
while($pWidth > $img['width'] || $pHeight > $img['height']) {
|
// we scale down the target dimensions to fit within the image dimensions,
|
||||||
// favor the smallest dimension
|
// with respect to the target dimensions ratio
|
||||||
if($pWidth > $img['width']) {
|
$ratioSource = $img['height'] / $img['width'];
|
||||||
$pWidth = $img['width'];
|
$ratioTarget = $targetHeight / $targetWidth;
|
||||||
$pHeight = $this->getProportionalHeight($pWidth);
|
if($ratioSource >= $ratioTarget) {
|
||||||
}
|
// ratio is equal or target fits into source
|
||||||
|
$pWidth = $targetWidth = $img['width'];
|
||||||
if($pHeight > $img['height']) {
|
$pHeight = $img['height'];
|
||||||
$pHeight = $img['height'];
|
$targetHeight = ceil($pWidth * $ratioTarget);
|
||||||
$pWidth = $this->getProportionalWidth($pHeight);
|
} else {
|
||||||
}
|
// target doesn't fit into source
|
||||||
|
$pHeight = $targetHeight = $img['height'];
|
||||||
if($targetWidth > $pWidth) $targetWidth = $pWidth;
|
$pWidth = $img['width'];
|
||||||
if($targetHeight > $pHeight) $targetHeight = $pHeight;
|
$targetWidth = ceil($pHeight / $ratioTarget);
|
||||||
|
}
|
||||||
if(!$this->cropping) {
|
if($this->cropping) {
|
||||||
$targetWidth = $pWidth;
|
// we have to disable any sharpening method here,
|
||||||
$targetHeight = $pHeight;
|
// as the source will not be resized, only cropped
|
||||||
}
|
$this->sharpening = 'none';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -221,11 +221,11 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
|||||||
if(!$isModified && ($this->imageType == \IMAGETYPE_PNG || $this->imageType == \IMAGETYPE_GIF)) {
|
if(!$isModified && ($this->imageType == \IMAGETYPE_PNG || $this->imageType == \IMAGETYPE_GIF)) {
|
||||||
$result = @copy($srcFilename, $dstFilename);
|
$result = @copy($srcFilename, $dstFilename);
|
||||||
if(isset($image) && is_resource($image)) @imagedestroy($image); // clean up
|
if(isset($image) && is_resource($image)) @imagedestroy($image); // clean up
|
||||||
if(isset($image)) $image = null;
|
if(isset($image)) $image = null;
|
||||||
return $result; // early return !
|
return $result; // early return !
|
||||||
}
|
}
|
||||||
|
|
||||||
// process JPEGs
|
// process JPEGs
|
||||||
if(self::checkMemoryForImage(array(imagesx($image), imagesy($image), 3)) === false) {
|
if(self::checkMemoryForImage(array(imagesx($image), imagesy($image), 3)) === false) {
|
||||||
throw new WireException(basename($srcFilename) . " - not enough memory to copy the final image");
|
throw new WireException(basename($srcFilename) . " - not enough memory to copy the final image");
|
||||||
}
|
}
|
||||||
@@ -246,7 +246,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
|||||||
$this->prepareImageLayer($thumb, $image);
|
$this->prepareImageLayer($thumb, $image);
|
||||||
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $finalWidth, $finalHeight, $this->image['width'], $this->image['height']);
|
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $finalWidth, $finalHeight, $this->image['width'], $this->image['height']);
|
||||||
|
|
||||||
} else if(4 == $resizeMethod) { // 4 = resize and crop with aspect ratio
|
} else if(4 == $resizeMethod) { // 4 = resize and crop with aspect ratio, - or crop without resizing ($upscaling == false)
|
||||||
|
|
||||||
// we have to scale up or down and to _crop_
|
// we have to scale up or down and to _crop_
|
||||||
|
|
||||||
@@ -259,20 +259,6 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
|||||||
$sourceWidth = $this->image['width'];
|
$sourceWidth = $this->image['width'];
|
||||||
$sourceHeight = $this->image['height'];
|
$sourceHeight = $this->image['height'];
|
||||||
|
|
||||||
/*
|
|
||||||
* @todo figure out how to make zoom setting adjust coordinates to imagecopyresampled() calls
|
|
||||||
$zoom = is_array($this->cropping) && isset($this->cropping[2]) ? $this->cropping[2] : 0;
|
|
||||||
if($zoom > 1) {
|
|
||||||
$zoom = $zoom * 0.01;
|
|
||||||
$sourceWidth -= $sourceWidth * $zoom;
|
|
||||||
$sourceHeight -= $sourceHeight * $zoom;
|
|
||||||
$sourceX = $this->image['width'] - ($sourceWidth / 2);
|
|
||||||
$sourceY = $this->image['height'] - ($sourceHeight / 2);
|
|
||||||
$bgX = 0;
|
|
||||||
$bgY = 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
$thumb2 = imagecreatetruecolor($bgWidth, $bgHeight);
|
$thumb2 = imagecreatetruecolor($bgWidth, $bgHeight);
|
||||||
$this->prepareImageLayer($thumb2, $image);
|
$this->prepareImageLayer($thumb2, $image);
|
||||||
imagecopyresampled(
|
imagecopyresampled(
|
||||||
|
Reference in New Issue
Block a user