简体   繁体   English

使用subprocess.call裁剪图像

[英]Using subprocess.call to crop an image

I'm having trouble in my python script, and I don't understand it : 我在python脚本中遇到了麻烦,但我听不懂:

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

Returns " invalid argument - -crop " 返回“ 无效参数--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? 系统中是否有不止一个convert器? Try an absolute path to the command you want? 尝试找到所需命令的绝对路径?

What about using the python image library instead ? 改用python图片库呢? That seems much more reliable than to call a subprocess (especially for error handling...). 这似乎比调用子流程(尤其是用于错误处理...)要可靠得多。

file is a _____builtin_____ class. file是_____builtin_____类。 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. 再次检查我们的假设。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM