-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parameters for Image.open() #569
Comments
I am +1, I think, but @wiredfool will need to comment. Any precedent in any other API for doing this? |
I want to look carefully at the code before endorsing an api change. I'm at a tentative +1. |
@aclark4life The I was going to propose something like the following:
We already have the
the idea being that if
Perhaps slightly easier to read and write? Additionally, the |
Maybe this can go in 2.5.0 due in 3 months |
This is not truth. Mode is not "image mode", this is "file read mode" and it is always "r". First lines of if mode != "r":
raise ValueError("bad mode %r" % mode) I strongly disagree about passing
Currently that way is opening image and calling I agree what there should be some way to configure decoder, but i = Image.open(image)
i.draft(mode, size)
i.configure_decoder(jpeg2000={'layers': 4}) |
I'm not sure I understand your point about the As far as the I like the |
I created #1349 as a suggestion, but did not progress due to lack of a specific use for the API. |
im = Image.open(fp, mode='r', format_args={ 'JPEG2000': { 'layers': 4 } }) in this what is |
@Shivahk027 from PIL import Image
with open("Tests/images/hopper.png", "rb") as fp:
im = Image.open(fp, mode='r', format_args={ 'JPEG2000': { 'layers': 4 } }) Another way is just to use the path of the image. from PIL import Image
im = Image.open("Tests/images/hopper.png", mode='r', format_args={ 'JPEG2000': { 'layers': 4 } }) For more information, see https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.open Note however that |
Let's close this issue as it's not really progressed in many years. We can reopen if necessary. |
There are a few file formats that would benefit from the ability to pass parameters through the
Image.open()
method. This needs to be thought about carefully because there are clearly some parameters that are generic (e.g.mode
,size
anddpi
arguments, which could cause conversion or resizing, all of which can in some instances be supported directly by the image file plugin), while others are very format specific (e.g. the number of quality layers to load in a JPEG 2000 image).As of today, some image file plugins are essentially relying on the laziness of PIL’s loading machinery so that the user can call
open
and subsequently set some properties on the returned object beforeload
gets called. This is, IMO, pretty nasty.(I might be up for fixing this myself, but I want to file a bug report before doing any coding because I want the opinions of others on how this should work.)
The text was updated successfully, but these errors were encountered: