This is a continuation of #621536: Images without extensions do not resize. In that issue any image without an extension would not be resized. We now allow images to be resized by checking the image MIME type and then using fallback extensions if none exists. However in some situations the MIME type cannot be established through PHP's getimagesize(). This seems to only apply to images that do not provide both Content-Type and Content-Length headers.

In order to fix this problem, we would need to not use getimagesize() at all, but find some other method of getting the mimetype (and image dimensions) for external URLs.

Comments

quicksketch’s picture

From #621536, here are two images that were used as examples:

Now works: http://a123.g.akamai.net/f/123/12465/1d/www.nationalpost.com/news/canada...
Does not work: http://www.bloomberg.com/apps/data?pid=avimage&iid=ibRQEnKp6k_U

The difference that I can see is that the Bloomberg image does not contain a "Content-Length" header, which seems to throw off PHP's getimagesize().

jcisio’s picture

In this case, should we save the remote file first, then use getimagesize() on the local one? It works for me with the above example.

quicksketch’s picture

That sounds like a good solution jcisio. In truth that might offer a dramatic speed improvement because it would prevent image_resize_filter from making 2 http requests for each image. Right now we get the image size through getimagesize() on the remote image, then we retrieve and save the image again later. If we just saved the image to a temporary location before getting the image size, we might speed up the whole process quite a bit and avoid the getimagesize() problem.

quicksketch’s picture

Status: Active » Needs work
StatusFileSize
new2.02 KB
new2.03 KB

Well this looked like it was going to work but Bloomberg has thwarted us again. This patch makes the change suggested by jcisio (download the image first, then try to get its image size), but unfortunately Bloomberg has some kind of sniffer on incoming requests. Instead of getting the original image, I kept getting a placeholder image (see attached file). I tried imitating the headers of a browser but no matter what headers I used I still got the placeholder.

Oddly this approach also seemed to take quite a bit longer, but that might have just been the Bloomberg servers taking a long time to respond to the request.

quicksketch’s picture

Status: Needs work » Patch (to be ported)

The patch from #4 has been combined into #740724: Delete remote images from temp directory after resizing.

Unfortunately I don't think there's much we can do about Bloomberg's hot-linking protection. It's probably a violation of copyright to pull down images from such a source anyway. Image Resize Filter will not work with any image regardless of extension, but we can't fault servers for returning placeholder images if they have protections in place like this.

quicksketch’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.