Extending a PIL decoder

python, python-imaging-library

Solution

What I did to solve this was to derive from the `ImageFile.ImageFile` child belonging to the embedded format instead of `ImageFile.ImageFile` directly. Then in `_open()` I replaced `self.fp` with the file-like to the embedded image, and called the parent's `_open()`. I can't say that I'm particularly happy doing it this way, but it seems to have worked.

Problem

I have a file which contains a single image of a specific format at a specific offset. I can already get a file-like for the embedded image which supports `read()`, `seek()`, and `tell()`. I want to take advantage of an existing PIL decoder to handle the embedded image, but be able to treat the entire file as an "image file" in its own right. I have not been able to figure out how to do this given the documentation available and was wondering if anyone had any insights as to how I could do this.

Original source