yireo / Yireo_NextGenImages

44 stars 26 forks source link

ImageUrls with parameters are not converted #73

Closed jesperingels closed 4 months ago

jesperingels commented 9 months ago

Hi,

When a product image contains parameters like so: https://www.viavaishoes.com/media/catalog/product/5/9/59070-01-308_s.jpg?width=469&height=469&store=nl&image-type=small_image this image will not be converted.

The reason for this is this method: '\Yireo\NextGenImages\Util\HtmlReplacer::isAllowedByImageUrl' In this if statement:

        if (!preg_match('/\.(jpg|jpeg|png)$/', $imageUrl)) {
            return false;
        }

It checks if the imageUrl ends with .jpg, .jpeg or .png. But in this case it doesn't end with any of these file extensions because it has parameters.

These parameters are handled here by Magento: '\Magento\Catalog\Model\View\Asset\Image::getUrlWithTransformationParameters'

So when you use this default Magento functionality the image is not converted by the NextGenImages module.

To resolve this issue I have created this pull-request: https://github.com/yireo/Yireo_NextGenImages/pull/72 Please let me know if you agree with this issue and if the changes can / have been merged

jissereitsma commented 9 months ago

I'm a little wary to say that just matching for \.(jpg|jpeg|png) somewhere in an image string is going to be fine. What if there is some kind of CDN that converts images like test.png to test.png/cached.png? Sounds crazy, I know, but it could. A safer alternative would be to modify the regular expression to match for a possible query string. Let me first think about this.

jissereitsma commented 4 months ago

Merged anyway. Let's see what happens.