I'm doing some work with images, and want to support displaying files that can contain multiple images, such as GIF, TIFF and ICO. If I know the number of contained images ahead of time everything works great, but if I attempt to load using an index greater than the number of images, I get a segfault; this means that a solution based on try/except will not work.
Is there a way to inspect an image file ahead of time to determine the number of images, and hence the maximum index that can be used?
I'm doing some work with images, and want to support displaying files that can contain multiple images, such as GIF, TIFF and ICO. If I know the number of contained images ahead of time everything works great, but if I attempt to load using an index greater than the number of images, I get a segfault; this means that a solution based on try/except will not work.
Is there a way to inspect an image file ahead of time to determine the number of images, and hence the maximum index that can be used?
wx.Image.GetImageCount("image-filename")
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
I'm doing some work with images, and want to support displaying files that can contain multiple images, such as GIF, TIFF and ICO. If I know the number of contained images ahead of time everything works great, but if I attempt to load using an index greater than the number of images, I get a segfault; this means that a solution based on try/except will not work.
Is there a way to inspect an image file ahead of time to determine the number of images, and hence the maximum index that can be used?
>> I'm doing some work with images, and want to support
>> displaying files that can contain multiple images, such as GIF,
>> TIFF and ICO. If I know the number of contained images ahead of
>> time everything works great, but if I attempt to load using an
>> index greater than the number of images, I get a segfault; this
>> means that a solution based on try/except will not work.
>> Is there a way to inspect an image file ahead of time to
>> determine the number of images, and hence the maximum index that
>> can be used?
>
> wx.Image.GetImageCount("image-filename")
That doesn't seem to work for GIF files; the docs seem to imply that
this is only for TIFF and ICO formats, too. Is there anything else I
can try?
I'm doing some work with images, and want to support displaying files that can contain multiple images, such as GIF, TIFF and ICO. If I know the number of contained images ahead of time everything works great, but if I attempt to load using an index greater than the number of images, I get a segfault; this means that a solution based on try/except will not work.
Is there a way to inspect an image file ahead of time to determine the number of images, and hence the maximum index that can be used?
wx.Image.GetImageCount("image-filename")
That doesn't seem to work for GIF files; the docs seem to imply that this is only for TIFF and ICO formats, too.
Hmm... The GIF handler should be able to do it too, you may want to enter a bug report about it and see if anybody picks up the task.
Thanks! Combined with the imghdr module, I can detect GIFs and use that code, but use GetFrameCount() with TIFF and ICO.
Dabo's dImage control now allows you to choose the frame to display in multi-image files simply by setting the PictureIndex property. It also has a FrameCount property that works independently of image type.