[英]PHP escapeshellcmd() breaks ImageMagick convert command using '>' character
I'm using ImageMagick 6.6.9 on an Ubuntu 12 server. 我在Ubuntu 12服务器上使用ImageMagick 6.6.9。 The problem I have is that my ImageMagick convert command, which I run through PHP using the shell_exec
function (but have also tried exec
), has characters in it which the PHP escapeshellcmd
function escapes with a \\
我遇到的问题是,我使用shell_exec
函数(但也尝试使用exec
)通过PHP运行的ImageMagick转换命令中包含的字符使PHP escapeshellcmd
函数使用\\
转义\\
Here is my PHP code: 这是我的PHP代码:
$result = exec(escapeshellcmd($convertString));
Here is my sample convert command: 这是我的示例转换命令:
/usr/bin/convert "/Users/rich/Sites/example/1234.JPG" -quality 85 -auto-orient -thumbnail "640x88>" "/Users/rich/Sites/example/1234-thumb.jpg"
And finally here is the convert command after it has been run through escapeshellcmd
: 最后,这是通过escapeshellcmd
运行后的转换命令:
/usr/bin/convert "/Users/rich/Sites/example/1234.JPG" -quality 85 -auto-orient -thumbnail "640x88\\>" "/Users/rich/Sites/example/1234-thumb.jpg"
The problem is that the escaped \\>
character results in an ImageMagick error: 问题是转义的\\>
字符导致ImageMagick错误:
convert: invalid argument for option -thumbnail': 640x88> @ error/convert.c/ConvertImageCommand/2770. convert:选项-thumbnail的无效参数':640x88> @ error / convert.c / ConvertImageCommand / 2770。
Does anyone know of a way that I can get around this? 有人知道我可以解决这个问题的方法吗? I have trawled the ImageMagick documentation and while they acknowledge the problem they don't seem to provide any other way of resizing an image without using the special unix characters: 我已经拖曳了ImageMagick文档,尽管他们确认了问题,但他们似乎没有提供其他任何不使用特殊unix字符来调整图像大小的方法:
The Only Shrink Flag ('>' flag) is a special character in both UNIX Shell and in Window batch scripts, and you will need to escape that character (using backslash '>' in shell, and '^>' in windows batch). 在UNIX Shell和Window批处理脚本中,Only Shrink标志('>'标志)是一个特殊字符,您将需要对该字符进行转义(在shell中使用反斜杠'>',在Windows批处理中使用'^>') 。 It is also special in and HTML web pages, so PHP scripts also may need some special handling. 它和HTML网页也很特殊,因此PHP脚本也可能需要特殊处理。
Many thanks in advance. 提前谢谢了。
原来,我在-thumbnail "640x88\\>"
大小选项周围有多余的"
(引号)。作为参考,正确的转义转换命令应为:
/usr/bin/convert "/Users/rich/Sites/example/1234.JPG" -quality 85 -auto-orient -thumbnail 640x88\\> "/Users/rich/Sites/example/1234-thumb.jpg"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.