mmikkel / Retcon-Craft

A collection of powerful Twig filters for modifying HTML
MIT License
79 stars 9 forks source link

Feature Request: dont apply transforms if image is smaller then the target transformation size #37

Closed krizzzly closed 1 year ago

krizzzly commented 2 years ago

Hi,

adding the following lines enables us to leave out images that are too small for the desired transformation

vendor/mmikkel/retcon/src/library/RetconHelper.php:256

$originalImageUrl =  $basePath . $imageUrlInfo['path'];
$originalImageInfo = getimagesize ( $originalImageUrl );
$originalImageWidth = $originalImageInfo[0];
$originalImageHeight = $originalImageInfo[1];

if ($originalImageWidth < $transformWidth) {

    return (object)[
        'url' => $imageUrlInfo['path'],
        'width' => $originalImageWidth,
        'height' => $originalImageHeight
    ];
}

Maybe we could add a parameter to the twig config array to apply this effect.

Kind regards

mmikkel commented 2 years ago

Sorry for the late response.

This should be covered by either Craft's upscaleImages setting, or the Imager plugin's allowUpscale setting, depending on which one Retcon is using to create the transforms.

tyssen commented 1 year ago

I've encountered this too and I created an issue with Craft because I thought the upscaling was occurring both with and without Retcon.

Turns out that when outside Retcon, images were being created in transform folders, but weren't actually being scaled up. But when testing the same images inside Retcon, they do get scaled up.

Iwona from Craft has pointed out where she thinks the problem lies. It seems that the scaleIfSmaller parameter is set to true in all cases.

mmikkel commented 1 year ago

This has been fixed for the next release.