ImageMagick Issue

Sick Monkey sickcodemonkey at gmail.com
Thu May 31 21:08:05 EDT 2007


I ran into another slight problem.  And I attempted to fix it, but have not
been able to do so yet.  If a filename does not contain a space, then this
method works like a charm.  But if there is a space then the code throws a
nasty error.

import os
import subprocess
from os import *
imagefile = "/somedir/images/david.huggins/Photo 1.jpg"
cmdw = "identify -format %w '"+imagefile+"'"
cmdh = "identify -format %h '"+imagefile+"'"
pw = subprocess.Popen(cmdw.split(), stdout=subprocess.PIPE, stderr=
subprocess.STDOUT)
ph = subprocess.Popen(cmdh.split(), stdout=subprocess.PIPE, stderr=
subprocess.STDOUT)
w = pw.stdout.read().strip()
h = ph.stdout.read().strip()

------------
identify: Unable to open file ('/somedir/images/david.huggins/Photo) [No
such file or directory].
identify: Unable to open file (1.jpg') [No such file or directory].
identify: Missing an image file name [No such file or directory].
identify: Unable to open file ('/somedir/images/david.huggins/Photo) [No
such file or directory].
identify: Unable to open file (1.jpg') [No such file or directory].
identify: Missing an image file name [No such file or directory].
Traceback (most recent call last):


On 5/31/07, Facundo Batista <facundo at taniquetil.com.ar> wrote:
>
> Sick Monkey wrote:
>
> > When I run the following command:
> > ozdon at SickCodeMonkey david.huggins]# identify -format %w
> > '/someDIR/images/david.huggins/100_0264.JPG'
>
> >From Python interpreter:
>
> >>> cmd = "identify -format %w test.jpg"
> >>> p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=
> subprocess.STDOUT)
> >>> t = p.stdout.read()
> >>> p.stdout.close()
> >>> t
> '50\n'
> >>>
>
> >From command line:
>
> facundo at expiron:~$ identify -format %w test.jpg
> 50
> facundo at expiron:~$
>
> Regards,
>
> --
> .   Facundo
> .
> Blog: http://www.taniquetil.com.ar/plog/
> PyAr: http://www.python.org/ar/
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070531/5edf94ea/attachment.html>


More information about the Python-list mailing list