staempfli / magento2-module-image-resizer

Magento 2 Module to add simple image resizing capabilities in all blocks and .phtml templates
92 stars 32 forks source link

Fix CDN bug #19

Closed mbernabeu closed 6 years ago

mbernabeu commented 6 years ago

in case you have a CDN and the path of media is for example https://media.website.es/ try to replace and break the relative path of the images.

jalogut commented 6 years ago

Hola @mbernabeu que tal todo?

I see the problem here. So if the images are not in a subfolder, $mediaPath is just / and that will replace all appearances of / when doing the str_replace.

If that's correct, then the right way to fix that will be to always replace only the first match and not all of them. That will work in all cases.

What do you think about the following change instead?

if (0 === strpos($imagePath, $mediaPath)) {
    $this->relativeFilename = substr_replace($imagePath, '', 0, strlen($mediaPath));
}

Could you please test it and update the PR, if you think that is a better solution?

Thanks!

mbernabeu commented 6 years ago

Hola @jalogut, muy bien tu que tal??

Yeah, it seems like the best way.

I just updated the changes right now.

jalogut commented 6 years ago

Great! I just created version 2.0.3 with this fix.

Thanks for your contribution. You are invited to visit me in Switzerland now ;)