]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/tools/img2img.py
1 #----------------------------------------------------------------------
2 # Name: wxPython.tools.img2img
3 # Purpose: Common routines for the image converter utilities.
8 # Copyright: (c) 2002 by Total Control Software
9 # Licence: wxWindows license
10 #----------------------------------------------------------------------
13 import sys
, os
, glob
, getopt
14 from wxPython
.wx
import *
17 def convert(file, maskClr
, outputDir
, outputName
, outType
, outExt
):
18 if os
.path
.splitext(file)[1].lower() == ".ico":
19 icon
= wxIcon(file, wxBITMAP_TYPE_ICO
)
20 img
= wxBitmapFromIcon(icon
)
22 img
= wxBitmap(file, wxBITMAP_TYPE_ANY
)
25 return 0, file + " failed to load!"
29 mask
= wxMaskColour(img
, maskClr
)
36 newname
= os
.path
.join(outputDir
,
37 os
.path
.basename(os
.path
.splitext(file)[0]) + outExt
)
38 if img
.SaveFile(newname
, outType
):
39 return 1, file + " converted to " + newname
41 img
= wxImageFromBitmap(img
)
42 if img
.SaveFile(newname
, outType
):
45 return 0, file + " failed to save!"
50 def main(args
, outType
, outExt
, doc
):
51 if not args
or ("-h" in args
):
60 opts
, fileArgs
= getopt
.getopt(args
, "m:n:o:")
61 except getopt
.GetoptError
:
78 for file in glob
.glob(arg
):
79 if not os
.path
.isfile(file):
81 ok
, msg
= convert(file, maskClr
, outputDir
, outputName
,