[Image-SIG] PIL - Opens tga as WbmpImageFile
fredrik at pythonware.com
Tue May 19 01:11:03 CEST 2009
On Mon, May 18, 2009 at 8:05 PM, Zac Burns <zac256 at gmail.com> wrote:
> On Mon, May 18, 2009 at 9:49 AM, Zac Burns <zac256 at gmail.com> wrote:
>> I have a script that is attempting to verify that an image is square.
>> This is accomplished using PIL.Image.open(filename).size
>> Within the context that the script is being run it is opening a tga as
>> a WbmpImageFile and reporting the size to be (2, 0).
>> However, printing repr(filename), copying the filename, and running
>> the line with that file from a fresh Python interpreter gives the
>> correct results.
>> PIL version is 1.1.6
>> Python version is 2.5.1
>> Zachary Burns
>> Aim - Zac256FL
>> Production Engineer (Digital Overlord)
>> Zindagi Games
> I locally patched the PIL.Image.open function to fix the bug and made
> some other improvements along the way.
> I'm not familiar with the PIL patch process and am not sure that the
> changes will be accepted by the community so I'll just post the code
> 1. More informative error message
> 2. Optimization: Moved import __builtin__ to top of file. (I'm not
> sure why but importing is relatively slow on my machine)
> 3. Factored shared code into an inline function
> 4. Does preinit and init before trying any plugins
> 5. Prefers the extension of the filepath
This will change the open semantic enough to risk breaking tons of
stuff, and also slow PIL down a lot for people using only common file
formats (and if importing the builtin module is slow on your machine,
something's fishy with your interpreter - that module is built into
the Python core).
The right way to fix this would be to make the TGA accept function
smarter to avoid false positives. Do you have any samples of the
problematic WBMP files that you can share? (feel free to mail them
directly to me; I won't make them public without explicit permission)
More information about the Image-SIG