Skip to content

Commit

Permalink
[BUGFIX] Fix cropScale calculation in ImageProcessingInstructions
Browse files Browse the repository at this point in the history
While refactoring the cropping information calculation in September
2023 by Benni Mack, the cropWidth / cropHeight and the offsets
were set to the wrong constructor arguments.

The patch reverses the order of the constructor of the CropArea
object.

Resolves: #103330
Related: #101957
Releases: main
Change-Id: I74b3b5fed604962b323e1017cf66695eb11d0a92
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83298
Reviewed-by: Simon Praetorius <simon@praetorius.me>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benjamin Franzke <ben@bnf.dev>
Reviewed-by: Benjamin Franzke <ben@bnf.dev>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Simon Praetorius <simon@praetorius.me>
Tested-by: core-ci <typo3@b13.com>
  • Loading branch information
bnf committed Mar 8, 2024
1 parent dea2362 commit cb887fb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
Expand Up @@ -215,10 +215,10 @@ public static function fromCropScaleValues(int $incomingWidth, int $incomingHeig
$offsetY = (float)(($obj->height - $obj->originalHeight) * ($cropOffsetVertical + 100) / 200);

$obj->cropArea = new Area(
(float)$cropWidth,
(float)$cropHeight,
$offsetX,
$offsetY,
(float)$cropWidth,
(float)$cropHeight,
);
}

Expand Down
Expand Up @@ -217,7 +217,7 @@ public static function fromCropScaleValuesImageDataProvider(): iterable
$result->width = 89;
$result->height = 800;
$result->useCropScaling = true;
$result->cropArea = new Area(50, 800, 19.5, 0);
$result->cropArea = new Area(19.5, 0, 50, 800);
yield 'Incoming instructions use "c" in width with given height' => [
100,
900,
Expand All @@ -234,7 +234,7 @@ public static function fromCropScaleValuesImageDataProvider(): iterable
$result->width = 50;
$result->height = 450;
$result->useCropScaling = true;
$result->cropArea = new Area(50, 450, 0, 225);
$result->cropArea = new Area(0, 225, 50, 450);
yield 'Incoming instructions use "c" in width but without height' => [
100,
900,
Expand All @@ -251,7 +251,7 @@ public static function fromCropScaleValuesImageDataProvider(): iterable
$result->width = 72;
$result->height = 650;
$result->useCropScaling = true;
$result->cropArea = new Area(50, 650, 13.2, 0);
$result->cropArea = new Area(13.2, 0, 50, 650);
yield 'Incoming instructions use "c" in width on both sides' => [
100,
900,
Expand All @@ -268,7 +268,7 @@ public static function fromCropScaleValuesImageDataProvider(): iterable
$result->width = 89;
$result->height = 800;
$result->useCropScaling = true;
$result->cropArea = new Area(50, 800, 23.4, 0);
$result->cropArea = new Area(23.4, 0, 50, 800);
yield 'Incoming instructions use "c" in width on both sides with given height' => [
100,
900,
Expand Down
Expand Up @@ -172,16 +172,12 @@ public static function basicUsageScalingCroppingDataProvider(): \Generator
200,
200,
];
// Throws error "/usr/bin/gm convert: geometry does not contain image (unable to crop image)."
// It's not strictly necessary to test this as the next case makes sure that the values are passed through correctly
/*
yield 'cropped' => [
'<f:image src="fileadmin/ImageViewHelperTest.jpg" width="100c" height="100c" />',
'@^<img src="(fileadmin/_processed_/5/3/csm_ImageViewHelperTest_.*\.jpg)" width="100" height="100" alt="" />$@',
100,
100,
];
*/
yield 'masked width' => [
'<f:image src="fileadmin/ImageViewHelperTest.jpg" width="300m" height="300m" />',
'@^<img src="(fileadmin/_processed_/5/3/csm_ImageViewHelperTest_.*\.jpg)" width="300" height="225" alt="" />$@',
Expand Down
Expand Up @@ -172,16 +172,12 @@ public static function basicScalingCroppingDataProvider(): \Generator
200,
200,
];
// Throws error "/usr/bin/gm convert: geometry does not contain image (unable to crop image)."
// It's not strictly necessary to test this as the next case makes sure that the values are passed through correctly
/*
yield 'cropped' => [
'<f:uri.image src="fileadmin/ImageViewHelperTest.jpg" width="100c" height="100c" />',
'@^(fileadmin/_processed_/5/3/csm_ImageViewHelperTest_.*\.jpg)$@',
100,
100,
];
*/
yield 'masked width' => [
'<f:uri.image src="fileadmin/ImageViewHelperTest.jpg" width="300m" height="300m" />',
'@^(fileadmin/_processed_/5/3/csm_ImageViewHelperTest_.*\.jpg)$@',
Expand Down

0 comments on commit cb887fb

Please sign in to comment.