Calling ImageMagick's convert
clp at rebertia.com
Mon Dec 22 09:33:56 CET 2008
On Mon, Dec 22, 2008 at 12:15 AM, cmr.Pent at gmail.com <cmr.Pent at gmail.com> wrote:
> Hello group!
> I'm a Python beginner. I'm trying to call ImageMagick's convert
> program from my code.
> My OS is Debian testing, and my version of Python is 2.5.
> I've just stumbled upon a problem:
> (1) subprocess.call('convert in.png -resize 640x480 out.png', shell =
> works, but none of the following does:
> (2) subprocess.call('convert in.png -resize 640x480 out.png')
> (3) subprocess.call(['convert', 'in.png', '-resize 640x480',
I think this needs to be:
subprocess.call(['convert', 'in.png', '-resize', '640x480', 'out.png'])
Otherwise, it gets '-resize 640x480' as a single escaped option when
it's really 2 options, which is the error message you're getting.
You have to split the arguments up just like the shell would, which
basically means at whitespace unless quoting is used, which is not the
Follow the path of the Iguana...
> (4) subprocess.call(['convert', 'in.png', '-resize 640x480',
> 'out.png'], shell = True)
> In these cases, convert program says 'unrecognized option -resize
> At the same time,
> subprocess.call(['ls', '-l'])
> works as expected.
> I'd like to use variant (3), as it seems the most handy. I don't
> understand why is shell = True required in case of convert. Is it a
> bug in Python, in ImageMagick, or am I missing something very basic
> Any hint appreciated.
More information about the Python-list