contao/image

Prevent resizing of images when resize mode is proportional and width and height of the image equal

devkev16 opened this issue · 2 comments

The ResizeConfiguration has a method where it checks whether an resize is unnecessary. Theres a missing check whether the height and width on the image are already equal when the resize mode is "proportional".

One good reason to change this behavior is: The image URLs don't change during an upgrade from an older version, this could be bad in perspective of seo (google images rankings).

This function:

/**
* Returns true if the resize would have no effect.
*/
public function isEmpty(): bool
{
return 0 === $this->width && 0 === $this->height && 0 === $this->zoomLevel;
}

Would need to check it like this:

    /**
     * Returns true if the resize would have no effect.
     */
    public function isEmpty(): bool
    {
        $size_and_mode_proportional = ($this->width === $this->height) && ($this->mode === self::MODE_PROPORTIONAL);

        return (0 === $this->width
            && 0 === $this->height
            && 0 === $this->zoomLevel)
            || $size_and_mode_proportional;
    }
ausi commented

I think I don’t fully understand that.

Resizing images for example to 100 by 100 in mode proportional would mean that landscape images get resized to 100 pixel width and portrait images to 100 pixel height. isEmpty() must not return true in this case because an actual resize of the image is necessary.

Can you give an example of how your code that does the resize looks like?

ausi commented

@devkev16 feel free to reopen this issue if you have further details.