Handling broken thumbs

#1

From time to time, we’ve got issues with image thumbnails not being generated correctly. This is most likely a server issue (timeout, memory, whatever): the final image has the proper ratio and size but is only partly rendered, e. g. the upper quarter or upper half, the rest is grey. Usually, on next load, everything is fine again.

With caching enabled, though, Kirby stores this broken image. :scream:

Is there a way for Kirby to determine if thumb generation was actually successful before generating the cache file?

#2

What thumbdriver are you using? Maybe switching to IM will clear up the issue. You would have to check that the file is valid, and the problem is that most images, particularly jpegs can be read if if the file is half missing. As long as the header is intact, it will read as much as it can. So the trick is deciding how corrupt is corrupt :slight_smile: A successful generation may not equate to a good generation.

#3

We haven’t set anything specifically so I guess we use GD by default.
Is Image Magic a drop in replacement or do I have to keep any side effects in mind when switching?

That sounds like there is nothing I can really do, right. Because the images are served, so the headers must be fine.

#4

You need it installed on the server, but it usually is. GD is more common, but in my experience with image heavy sites, the results are better with IM.

Yes, i’m afraid thats probably the case, The jpeg format is actually pretty forgiving (it’s how criminals get caught, even after they tried to shred their hard drive). You can even hide files inside jpegs and still have the image read back just fine in a graphics programs without revelling the secret. it’s called Steganography.

#5

It’s installed on the server so that wouldn’t be a problem. Will check if switching helps.

Thanks, @jimbobrjames.

#6

@nilshoerrmann Are the thumbs really only half-way created or do they just not render correctly in the page?

#7

It’s really a creation problem. If I open the cached thumbs from the /media folder I see the same effect.

#8

are the images too large in width and height? maybe your server (shared etc) does not allow you enough memory to work on the image? both gd and im will work with uncompressed data. try saving it as tiff to get a rough estimate on memory requirement of a file.

also try running the image to an optimizer like imageoptim before thumb creation to remove fancy color profiles.

#9

Yes, the images are large but optimized with ImageOptim already.

We raised the memory limit already and so far everything is fine. I just hoped there was a way to exclude broken images from the cache (which doesn‘t seem to be the case).

#10

Maybe we can add an extra mime type check after the thumbnail generation and only keep valid images.

#11

I’m not sure that would work. If the headers ok, it would get a mime type back (i think), but the rest of the file might by corrupt or partially missing. I think you would have to check for an end of file marker instead, no idea how to actually do that :slight_smile: Jpegs can still be read of there is no end of file marker, but if it is there then you know the file is complete.