JAR equivalent in Gordon McMillan's Installer
Chris Liechti
cliechti at gmx.net
Fri Feb 15 19:46:07 EST 2002
"Mike C. Fletcher" <mcfletch at geocities.com> wrote in
news:mailman.1013812227.6703.python-list at python.org:
> wxImages can be loaded from strings. See the wxPython Wiki entry on
> working with images (particularly the sections on PIL and Numeric):
ok just tried this:
------------
import zipfile
from wxPython.wx import *
wxInitAllImageHandlers() #init wx stuff
#convert file
bmp = wxImage('img.png', wxBITMAP_TYPE_PNG)
raw = bmp.GetData()
zipf = zipfile.ZipFile('hello.zip','w')
info = zipfile.ZipInfo('hello.%d.%d' % (bmp.GetWidth(), bmp.GetHeight
()))
info.compress_type=zipfile.ZIP_DEFLATED
zipf.writestr(info, raw)
del zipf
#use it
zipf = zipfile.ZipFile('hello.zip','r')
entry = zipf.namelist()[0]
name,w,h = entry.split('.')
raw = zipf.read(entry)
img = wxEmptyImage(int(w), int(h))
img.SetData(raw)
#img = img.Rotate(45, (10,10)) #just for fun
img.SaveFile("hello.png", wxBITMAP_TYPE_PNG)
--------
you can use wxPython to convert the images to strings, save them to a
zip using the zipfile module. the image sizes have to be saved
separately. i've choosen to stuff them into the filename.
storing uncompressed images in a zip isn't that bad, as e.g png or gif
also uses some similar compression algos. (in my test the zip was
smaller than the original png)
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list