JamesHeinrich / phpThumb

phpThumb() - The PHP thumbnail generator
Other
315 stars 141 forks source link

Wrong Mime Type of product images #222

Closed borislav123 closed 1 month ago

borislav123 commented 1 month ago

Hello, all. We are using this good script in a website but we detected an issue.

1 . Product image - tyre - /used in product page - example - [https://diana-ltd.com/tire?46586] ) - Right click on the image - Open image in new tab / https://diana-ltd.com/cache/image/b65336a9b76813cc4bdf2f11be923bb0/AHrz-LM005.png

  1. Image test - with this tool - [https://jimpl.com] - (https://jimpl.com/results/hMrpfTRZr3ZXdqU6NCaBAcX6?target=exif) - when you put your image URL path - / https://diana-ltd.com/cache/image/b65336a9b76813cc4bdf2f11be923bb0/AHrz-LM005.png /

  2. Result - image is PNG but we send to the browser Mime Type - image/jpeg .

large-View-or-remove-EXIF-metadata-from-the-photo-Jimpl

How to make mime type to be proper - to become image/png.?

Thank you.

JamesHeinrich commented 1 month ago

The image at https://diana-ltd.com/thumbs/files/models/3531/220207-134553-Uniroyal_RainExpert_5_ProductPicture_30.png is PNG (with transparency). The image at https://diana-ltd.com/cache/image/4c2bdb024973262e66ce8544f88cd327/220207-134553-Uniroyal_RainExpert_5_ProductPicture_30.png is a JPEG (doesn't matter what the filename is called).

Actually you have some interesting URL rewriting going on -- https://diana-ltd.com/cache/image/4c2bdb024973262e66ce8544f88cd327/220207-134553-Uniroyal_RainExpert_5_ProductPicture_30.jpg also works, gives you the identical JPEG image as the above .png link. In fact everything after the hash is ignored, so you can get https://diana-ltd.com/cache/image/4c2bdb024973262e66ce8544f88cd327/ and it's still the same JPEG image.

borislav123 commented 1 month ago

Hello, @JamesHeinrich . Thank you for your explanation. I think I got it.

But then why the picture looks like this -

diana-ltd-com-cache-image-4c2bdb024973262e66ce8544f88cd327-

and not like this -

220207-134553-Uniroyal_RainExpert_5_ProductPicture_30-png-356×500-

When I right click on the image - Open image in new tab ....

Thank you.

JamesHeinrich commented 1 month ago

The server isn't returning any MIME type with the request, so the browser displays it as text.

print_r(get_headers('https://diana-ltd.com/cache/image/4c2bdb024973262e66ce8544f88cd327/220207-134553-Uniroyal_RainExpert_5_ProductPicture_30.png'));

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Date: Thu, 20 Jun 2024 13:49:06 GMT
    [2] => Transfer-Encoding: chunked
    [3] => Connection: close
    [4] => x-frame-options: SAMEORIGIN
    [5] => last-modified: Fri, 31 May 2024 06:49:23 GMT
    [6] => Cache-Control: max-age=2592000
    [7] => expires: Fri, 19 Jul 2024 16:42:05 GMT
    [8] => vary: Accept-Encoding
    [9] => x-content-type-options: nosniff
    [10] => x-xss-protection: 1; mode=block
    [11] => strict-transport-security: max-age=31536000
    [12] => CF-Cache-Status: HIT
    [13] => Age: 76021
    [14] => Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=b2OJy0%2FzEBUVAaEmrUiAFX4vWPNcqbZVrUiRYN4oXxMvxXvaYjmJsY%2Fre%2FqMe9QR34QK%2F7bVmGjepyE2qZtL%2BPKLk0%2FoZB5Q1eZPvlNwgj%2FIhDseHGoYEbKi14YcE4NHBXE2gdweFm8U2sA%3D"}],"group":"cf-nel","max_age":604800}
    [15] => NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
    [16] => Server: cloudflare
    [17] => CF-RAY: 896c38631ecc61a9-ORD
)
borislav123 commented 1 month ago

Thank you, so much, @JamesHeinrich .

How it could be solved?

JamesHeinrich commented 1 month ago

I have no idea. It's possibly something related to CloudFlare (which I have no experience with). It doesn't appear to be related to phpThumb.

borislav123 commented 1 month ago

Got it. Thank you.