yireo / Yireo_NextGenImages

45 stars 28 forks source link

Issue with hard coded image with no protocol specified #34

Closed chrisastley closed 2 years ago

chrisastley commented 2 years ago

I've noticed a recurring error in the Magento logs;

[2022-06-26T15:20:53.193697+00:00] main.CRITICAL: Exception: Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: Not a JPEG file: starts with 0x00 0x00 in /var/www/vhosts/domain.co.uk/htdocs/vendor/rosell-dk/webp-convert/src/Convert/Converters/Gd.php on line 219 in /var/www/vhosts/domain.co.uk/htdocs/vendor/magento/framework/App/ErrorHandler.php:61

When I enabled the debug and logging I found this;

[2022-06-26T15:20:53.984614+00:00] main.NOTICE: Source cached image does not exists: /var/www/vhosts/domain.co.uk/htdocs/pub//assets.pinterest.com/images/pidgets/pin_it_button.png: array ( 'path' => '/var/www/vhosts/domain.co.uk/htdocs/pub//assets.pinterest.com/images/pidgets/pin_it_button.png', ) [] []

When I checked for the URL within the template I found that it is coded with no protocol.

-bash-4.2$ grep -rnPe 'pin_it_button.png' app/ app/code/Mirasvit/RewardsBehavior/view/frontend/templates/buttons/pinterest/pin.phtml:11:

I have temporarily added the https: to the 3rd party module. Could you look to resolve the issue so that these URLs aren't detected as being an absolute URL.

jissereitsma commented 2 years ago

That's a strange issue. The image you are talking about is a PNG image, so imagecreatefromjpeg shouldn't be at play here at all (which is for a JPEG). The Yireo WebP extension uses the rosell-dk/webp-convert package for this. Looking at the code that throws the warning, this would be due to a wrong MIME-type that is being detected, which is again driven by another package rosell-dk/image-mime-type-guesser which seems to be using a PHP function exif_imagetype. Could you check if this PHP function is indeed available?

I tested a couple of things with URLs myself and found that a URL starting with // (so, no protocol specified) was actually not being picked up properly at all as being a local image that could be converted. I've added fixes for this in yireo/magento2-next-gen-images version 0.3.6. Could you see if that makes a change for you?

chrisastley commented 2 years ago

Hi,

Thanks for the quick fix. As you say, how the image type in the error is different between logs is odd but since applying the update last night no more errors have occurred.

Regards