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($targetHeight == $originalTargetHeight && 1 + $targetHeight == $pHeight) $pHeight = $pHeight - 1;
|
||||
|
||||
if(!$this->upscaling) {
|
||||
// we are going to shoot for something smaller than the target
|
||||
|
||||
while($pWidth > $img['width'] || $pHeight > $img['height']) {
|
||||
// favor the smallest dimension
|
||||
if($pWidth > $img['width']) {
|
||||
$pWidth = $img['width'];
|
||||
$pHeight = $this->getProportionalHeight($pWidth);
|
||||
}
|
||||
|
||||
if($pHeight > $img['height']) {
|
||||
if(!$this->upscaling && ($img['width'] < $targetWidth || $img['height'] < $targetHeight)) {
|
||||
// via @horst-n PR #118:
|
||||
// upscaling is not allowed and we have one or both dimensions to small,
|
||||
// we scale down the target dimensions to fit within the image dimensions,
|
||||
// with respect to the target dimensions ratio
|
||||
$ratioSource = $img['height'] / $img['width'];
|
||||
$ratioTarget = $targetHeight / $targetWidth;
|
||||
if($ratioSource >= $ratioTarget) {
|
||||
// ratio is equal or target fits into source
|
||||
$pWidth = $targetWidth = $img['width'];
|
||||
$pHeight = $img['height'];
|
||||
$pWidth = $this->getProportionalWidth($pHeight);
|
||||
}
|
||||
|
||||
if($targetWidth > $pWidth) $targetWidth = $pWidth;
|
||||
if($targetHeight > $pHeight) $targetHeight = $pHeight;
|
||||
|
||||
if(!$this->cropping) {
|
||||
$targetWidth = $pWidth;
|
||||
$targetHeight = $pHeight;
|
||||
$targetHeight = ceil($pWidth * $ratioTarget);
|
||||
} else {
|
||||
// target doesn't fit into source
|
||||
$pHeight = $targetHeight = $img['height'];
|
||||
$pWidth = $img['width'];
|
||||
$targetWidth = ceil($pHeight / $ratioTarget);
|
||||
}
|
||||
if($this->cropping) {
|
||||
// we have to disable any sharpening method here,
|
||||
// as the source will not be resized, only cropped
|
||||
$this->sharpening = 'none';
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -246,7 +246,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
||||
$this->prepareImageLayer($thumb, $image);
|
||||
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_
|
||||
|
||||
@@ -259,20 +259,6 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
||||
$sourceWidth = $this->image['width'];
|
||||
$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);
|
||||
$this->prepareImageLayer($thumb2, $image);
|
||||
imagecopyresampled(
|
||||
|
Reference in New Issue
Block a user