Note that there are some explanatory texts on larger screens.

plurals
  1. PODisplay an image read from a zip archive python
    primarykey
    data
    text
    <p>I want to create a comic archive reader in python as an exercise to teach myself more python but I've been having troubles trying to read different image files from a zip archive without extracting the files and then display them.</p> <p>I found a website with an example (http://www.python-forum.org/pythonforum/viewtopic.php?f=4&amp;t=3607) that could only display .gif images. The example uses <code>PhotoImage</code> (The Tkinter version not the PIL version) which can accept a 64bit encoded string instead of an actual file. From most of my research it looks like PIL is what I want to use to deal with images other than gif but I can't find a way to call <code>PIL.ImageTk.PhotoImage</code> in a similar way to the <code>Tkinter.PhotoImage</code>. to take a stream of data instead of an actual file.</p> <p>Is there any way that I can hand the data received from <code>zipfile.read()</code> to <code>PIL.ImageTk.PhotoImage</code>? Is there another library I could use to handle the images? Tkinter is not a requirement for the program I'm writing so if there is a better widget framework that I should be using I don't mind changing.</p> <p>EDIT: So I figured a way to do this with PIL and tkinter.</p> <pre><code>z = zipfile.ZipFile("zipfile.zip", "r") data = z.read(z.namelist()[0]) #Read in the first image data dataEnc = StringIO(data) #Encode the raw data to be used by Image.open() img = Image.open(dataEnc) #Open the image pimg = ImageTk.PhotoImage(img) #Make tk compatible image </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload