]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/tools/img2img.py
4d73512762917d12afc5b9419655ada5536e9250
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 *
16 # some bitmap related things need to have a wxApp initialized...
18 wxInitAllImageHandlers()
20 def convert(file, maskClr
, outputDir
, outputName
, outType
, outExt
):
21 if os
.path
.splitext(file)[1].lower() == ".ico":
22 icon
= wxIcon(file, wxBITMAP_TYPE_ICO
)
23 img
= wxBitmapFromIcon(icon
)
25 img
= wxBitmap(file, wxBITMAP_TYPE_ANY
)
28 return 0, file + " failed to load!"
32 mask
= wxMaskColour(img
, maskClr
)
39 newname
= os
.path
.join(outputDir
,
40 os
.path
.basename(os
.path
.splitext(file)[0]) + outExt
)
41 if img
.SaveFile(newname
, outType
):
42 return 1, file + " converted to " + newname
44 img
= wxImageFromBitmap(img
)
45 if img
.SaveFile(newname
, outType
):
48 return 0, file + " failed to save!"
53 def main(args
, outType
, outExt
, doc
):
54 if not args
or ("-h" in args
):
63 opts
, fileArgs
= getopt
.getopt(args
, "m:n:o:")
64 except getopt
.GetoptError
:
81 for file in glob
.glob(arg
):
82 if not os
.path
.isfile(file):
84 ok
, msg
= convert(file, maskClr
, outputDir
, outputName
,