当前位置: 动力学知识库 > 问答 > 编程问答 >

python - Using subprocess.call to crop an image

问题描述:

I'm having trouble in my python script, and I don't understand it :

subprocess.call(['convert', file, '-crop', '80x10+90+980', '+repage', 'test.jpg'])

Returns "invalid argument - -crop"

But if I run this from the command line, it works fine :

convert test.jpg -crop 80x10+90+980 +repage test.jpg

What am I missing here ?

网友答案:

Is there more than one convert in the system? Try an absolute path to the command you want?

网友答案:

What about using the python image library instead? That seems much more reliable than to call a subprocess (especially for error handling...).

网友答案:

file is a _____builtin_____ class. Overriding it may produce unwanted results. Try using a different variable name.

网友答案:

I've actually tried your code:

>>> import subprocess
>>> subprocess.call(['convert', 'capa.jpg', '-crop', '80x10+90+980', '+repage', 'capa2.jpg'])
0
>>> 

And it works for me!

So you must have something wrong, somewhere else. Check our assumptions again.

分享给朋友:
您可能感兴趣的文章:
随机阅读: