Added bit_depth attribute to PngImageFile#9601
Added bit_depth attribute to PngImageFile#9601ajslater wants to merge 4 commits intopython-pillow:mainfrom
Conversation
Could you elaborate on this? Pillow attempts to deal with this kind of low level information so you don't have to. You should be able to infer a less-precise bit depth from The following code would let you determine a numeric value for the bit depth at the moment. from PIL import Image, PngImagePlugin
with Image.open("Tests/images/hopper.png") as im:
for bitDepth_colorType, mode_rawmode in PngImagePlugin._MODES.items():
if im.png.im_rawmode == mode_rawmode[1]:
print("Bit depth:", bitDepth_colorType[0])I acknowledge my suggestion is inelegant and uses a private property. If we did go with your suggestion, I think it would be better as another key in
I find this comment confusing. What do you think is undone about this PR? Or are you just saying that you're willing to accept feedback? |
In my application, called picopt, I do PNG lossless optimization. The bit depth detection code I have is actually used to disqualify high bit depth pngs from using the PngOut optimize which doesn't accept them. I've had this code rattling around my app for a while now and always wondered if PIllow users might find this extra information useful. Idk if it really fits what Pillow wants to accomplish, but I thought I'd run it by you. I just tested your solution using _MODES and it works in my code.
Yes, that. I've never contributed to Pillow before and was unsure if this PR met the standards and practices of this repo. I suppose the questions are:
|
I find it useful when working with PNGs to know their bit depth and since i use Pillow to detect image formats as well as manipulate images I thought it might be a useful addition.
This just reads a well known byte from the png stream and stores it on the PngImageFile.
Tell me if this looks useful and I can modify this PR to work well as a Pillow contribution.