Using full-size embedded jpg/png images in a wx application

Now that the problem of running img2py has been solved,
see "Trying to use the img2xxx utils in the wx\tools directory"

I need to ask some advice on embedding a large number of full-size jpg
images into a wxpython program.

I've got 135 jpgs I want to have accessible in a wx app, as part of a
database.

Unfortunately, converting them to png so they can be embedded in a .py
file makes that file 55 MBs alone.

I could leave them as jpgs, but then 135 additional files would need
to be distributed with the exe.
I don't think non-python files can be embedded into a py2exe program-
and still be accessible by the program.

1. Why is the png format used for embedding images into a python file.
PNG images so large compared to jpgs.
2. Are there any other options available that i don't know about?

Hi,

Now that the problem of running img2py has been solved,
see "Trying to use the img2xxx utils in the wx\tools directory"

I need to ask some advice on embedding a large number of full-size jpg
images into a wxpython program.

I've got 135 jpgs I want to have accessible in a wx app, as part of a
database.

Unfortunately, converting them to png so they can be embedded in a .py
file makes that file 55 MBs alone.

I could leave them as jpgs, but then 135 additional files would need
to be distributed with the exe.
I don't think non-python files can be embedded into a py2exe program-
and still be accessible by the program.

You can include them using the data_files option, e.g. something like this:
# copy image files
mygif = glob.glob(baseFolder+"\\program\\images\\*.gif")
myico = glob.glob(baseFolder+"\\program\\images\\*.ico")
mypng = glob.glob(baseFolder+"\\program\\images\\logo*.png")
myjpg = glob.glob(baseFolder+"\\program\\images\\*.jpg")
myimages = mygif + myjpg + myico + mypng

data_files += [("locale\\fr\\LC_MESSAGES", mylocaleFR),
....
                ("images", myimages),
                ("images\\others", myotherimages),
...
                ("lib\\Schemata", amaraschemata),]

This will store them in the "images" folder under your "dist" folder. In you application you then just have to ensure that you use the correct access path to load the images i.e. I use it like this with the above
wx.Bitmap('images/others/PythonPowered.png', wx.BITMAP_TYPE_PNG)

Or you could include them using something like InnoSetup.

Werner

···

On 10/09/2010 06:29, cappy2112 wrote:

1. Why is the png format used for embedding images into a python file.

The PNG format is lossless, JPEG is lossey. PGNs support transparency and alpha channels, JPEGs do not.

2. Are there any other options available that i don't know about?

When the .pyc file is generated it is byte compiled, so goes a lot of
the way back down then if the Py2exe compressed library options can be
used - this basically zips the .pyc files you are likely to find that
your inflation of the file size is not as bad as you are expecting.

There is still a hit at runtime where you have the whole image data in memory as a string and it will continue to exist after the wx.Bitmap has been created, used and thrown away. For that reason I would not use image embedding for large images, or even for lots of medium sized images.

You could ship your jpeg files within a single .zip file and either have
an install routine that unzips them to a working directory, (hit on hard
disc space but not on start-up time, or unzip them on start-up, (slower
start-up), and then delete them on exit, (saving the space).
Alternatively you could use the files directly as .jpeg from within a
single .zip file - just remember that python includes a zip library and
handles zip files and streams quite efficiently.

Yep, those would work. So would just adding the images to the installer tool and having it install them as individual files when the application is installed. Cappy also mentioned that they would be "part of a database" so loading the images in a table in the database would work too, and would make it easy to manage and extend the collection of images. It all depends on what is a good fit for your application's needs.

···

On 9/9/10 10:22 PM, GadgetSteve@live.co.uk wrote:

--
Robin Dunn
Software Craftsman