]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/tools/img2xpm.py
3 img2xpm.py -- convert several image formats to XPM
7 img2xpm.py [options] image_files...
11 -o <dir> The directory to place the .xpm file(s), defaults to
12 the current directory.
14 -m <#rrggbb> If the original image has a mask or transparency defined
15 it will be used by default. You can use this option to
16 override the default or provide a new mask by specifying
17 a colour in the image to mark as transparent.
19 -n <name> A filename to write the .xpm data to. Defaults to the
20 basename of the image file + '.xpm' This option overrides
25 import sys
, os
, glob
, getopt
, string
26 from wxPython
.wx
import *
28 wxInitAllImageHandlers()
30 if wxPlatform
== "__WXGTK__":
31 app
= wxPySimpleApp() # Blech! the GUI needs initialized before
32 # bitmaps can be created...
35 def convert(file, maskClr
, outputDir
, outputName
):
36 if string
.lower(os
.path
.splitext(file)[1]) == ".ico":
37 icon
= wxIcon(file, wxBITMAP_TYPE_ICO
)
38 img
= wxBitmapFromIcon(icon
)
40 img
= wxBitmap(file, wxBITMAP_TYPE_ANY
)
43 return 0, file + " failed to load!"
47 mask
= wxMaskColour(img
, maskClr
)
54 newname
= os
.path
.join(outputDir
, os
.path
.basename(os
.path
.splitext(file)[0]) + ".xpm")
55 if img
.SaveFile(newname
, wxBITMAP_TYPE_XPM
):
56 return 1, file + " converted to " + newname
58 img
= wxImageFromBitmap(img
)
59 if img
.SaveFile(newname
, wxBITMAP_TYPE_XPM
):
62 return 0, file + " failed to save!"
67 if not args
or ("-h" in args
):
76 opts
, fileArgs
= getopt
.getopt(args
, "m:n:o:")
77 except getopt
.GetoptError
:
94 for file in glob
.glob(arg
):
95 if not os
.path
.isfile(file):
97 ok
, msg
= convert(file, maskClr
, outputDir
, outputName
)
102 if __name__
== "__main__":