Skip to content
Snippets Groups Projects
Unverified Commit 3ffbdacf authored by Matt Glaman's avatar Matt Glaman Committed by GitHub
Browse files

Issue #3340734 by mglaman: Scale effect is with upscaling setting causes bad...

Issue #3340734 by mglaman: Scale effect is with upscaling setting causes bad parameters, does not return image (#193)

* DIT-1125 handle image scaling properly.
parent 9194a998
No related branches found
Tags 1.0.10
No related merge requests found
......@@ -121,13 +121,21 @@ final class EmbedCodeUrlBuilder {
case 'image_scale':
if ($effect['data']['width'] && $image_properties['aspect_ratio'] >= 1) {
$values['w'] = self::calculateScaleDimensions($image_properties['width'], self::getDimensionValue($effect['data']['width']), $effect['data']['upscale']);
$values['w'] = self::calculateScaleDimensions(
self::getDimensionValue($image_properties['width']),
self::getDimensionValue($effect['data']['width']),
$effect['data']['upscale']
);
break;
}
// If width is not set or set but ratio lower than 1.
if ($effect['data']['height']) {
$values['h'] = self::calculateScaleDimensions($image_properties['height'], self::getDimensionValue($effect['data']['height']), $effect['data']['upscale']);
$values['h'] = self::calculateScaleDimensions(
self::getDimensionValue($image_properties['height']),
self::getDimensionValue($effect['data']['height']),
$effect['data']['upscale']
);
}
break;
......@@ -173,7 +181,7 @@ final class EmbedCodeUrlBuilder {
* Returns the correct scale dimension.
*/
protected static function calculateScaleDimensions(int $original_dimension, int $scale_dimension, bool $upscale): int {
if (!$upscale && $original_dimension > $scale_dimension) {
if ($original_dimension > $scale_dimension) {
return $scale_dimension;
}
......
......@@ -34,6 +34,100 @@ class EmbedCodeUrlBuilderTest extends UnitTestCase {
);
}
/**
* Tests image scaling with a large source image.
*
* @param int $width
* The image width.
* @param int $height
* The image height.
* @param int $scale_width
* The image scale width.
* @param int $scale_height
* The image scale height.
* @param bool $upscale
* To upscale the image or not.
* @param array $result
* The expected result.
*
* @dataProvider largeImageUpscaleProvider
*/
public function testImageScaleWithLargeImage(int $width, int $height, int $scale_width, int $scale_height, bool $upscale, array $result): void {
self::assertEquals(
$result,
EmbedCodeUrlBuilder::mapImageEffects(
[
[
'uuid' => '97f71b20-1c2e-4633-a39b-d6535b242a10',
'id' => 'image_scale',
'weight' => 1,
'data' => [
'width' => $scale_width,
'height' => $scale_height,
'upscale' => $upscale,
],
],
],
[
'width' => $width,
'height' => $height,
'aspect_ratio' => $width / $height,
],
'uri'
)
);
}
/**
* Test data for image scaling.
*/
public static function largeImageUpscaleProvider() {
yield 'with upscale, horizontal' => [
8256,
5504,
450,
550,
TRUE,
[
'format' => 'web',
'w' => 450,
],
];
yield 'without upscale, horizontal' => [
8256,
5504,
450,
550,
FALSE,
[
'format' => 'web',
'w' => 450,
],
];
yield 'with upscale, vertical' => [
5504,
8256,
450,
550,
TRUE,
[
'format' => 'web',
'h' => 550,
],
];
yield 'without upscale, vertical' => [
5504,
8256,
450,
550,
FALSE,
[
'format' => 'web',
'h' => 550,
],
];
}
/**
* Array of effects and expected result.
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment