Fixing corrupt PNGs missing the IEND chunk
Managed to do this in Python with:
from PIL import Image
file_in = "test.png"
img = Image.open(file_in)
file_out = "test-fixed.png"
img.save(file_out)
Requires PIL/Pillow pip install Pillow
Related videos on Youtube
Titan
Updated on September 18, 2022Comments
-
Titan over 1 year
I have
.png
files outputted by a tool that converts.emf
s to.png
s but that doesn't add the IEND chunk to the end.Therefore, other tools, like ImageMagick, won't go near them as they detect them as corrupt:
> pngcheck test.png test.png file doesn't end with an IEND chunk
However, I can open the
.png
fine in desktop GUI image viewing applications, so my current workaround is to open it in these applications (e.g. Preview.app) and re-export the image, which then gets saved with the correct headers, etc.This obviously isn't scale-able, and I need something to work server side in an automated way.
How do I go about fixing the images, preferably with a method that can be automated and run server-side, e.g. using Python?
This is the image in question.
-
fixer1234 over 5 yearsThis thread was bumped because it doesn't have an accepted answer. The question is written as a product request, so it is attracting close votes. You might want to accept your own answer.