fix cross-device link error
[PyX.git] / contrib / imgconvert.py
blob7c35372bcb057b98b781f69a9fd55cdb63b7d603
1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*-
5 # Copyright (C) 2005 André Wobst <wobsta@users.sourceforge.net>
7 # epstopng is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # epstopng is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with epstopng; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 from optparse import OptionParser
22 from pyx import *
23 from pyx import version
25 parser = OptionParser(usage="usage: %prog -o output-file [-r resolution] image-file",
26 version="%prog " + version.version)
27 parser.add_option("-o", "--output",
28 type="string", dest="output",
29 help="output-file")
30 parser.add_option("-r", "--resolution",
31 type="string", dest="resolution", default=None,
32 help="resolution of the image in dpi (optional when available in the image data)")
33 (options, args) = parser.parse_args()
34 if len(args) != 1:
35 parser.error("can process a single image-file only")
37 try:
38 im = bitmap.jpegimage(args[0])
39 except ValueError:
40 from PIL import Image
41 im = Image.open(args[0])
42 compressmode = "Flate"
43 else:
44 compressmode = None
45 if options.resolution is None:
46 width = None
47 else:
48 width = im.size[0] / float(options.resolution) * unit.inch
49 c = canvas.canvas()
50 c.insert(bitmap.bitmap(0, 0, im, compressmode=compressmode, width=width))
51 c.writetofile(options.output)