shibukawa / imagesize_py

MIT License
222 stars 43 forks source link

Added support for BMP files #60

Open ExtReMLapin opened 1 year ago

ExtReMLapin commented 1 year ago

tested with 24bits bmp and 1bit bmp

marcoffee commented 1 year ago

@ExtReMLapin could you add support for BMPs with negative height?

You just have to change the unpack format specification to "<Ll" (or maybe "<ll" if you also want to supported signed width, but I don't know if width < 0 is allowed) and add height = abs(height), then it will work fine.

Here is an example (I had to zip it, because GitHub do not support .bmp images) negative-height.zip

Here is the same image, but converted to .png negative-height

In this example (if correctly parsed), it must consist of a 100 x 300 image where the top is a red square, the middle is a green square, and the bottom is a blue square. On the BMP header, the height is specified as -300, i.e., the struct.unpack call as-is would return (100, 4294966996).

ExtReMLapin commented 6 months ago

🤠 Done !