开发者

PHP exec commands and escaping special characters

So I'm using command line execs with php to perform Image Magick converts, and I'm having an issue with one that I'm pretty sure has to do with the '!' in it. Sometimes I may want to use my library to resize an image without keeping the aspect ratio, and Image Magick has a command that does just that. You simply append the max width and height values with an '!' Problem is I can't get it to work, and it just ignores the height limit completely. I figure its because '!' needs to be escaped, but I can't seem to get it to work. Can anyone tell me how I might get this command to work:

exec("convert $theFile -resize $max_Xx$max_Y! $theFile", $outputAry);

$theFile is the path to the image, and $max_X and max_Y are the width and height values passed in via what the user sets them to be. Without 开发者_C百科the '!' and it resizes while keeping the aspect ratio perfectly, but as it's written up there, it ignores the height and only resizes the width while keeping the original height. I've tried escaping it by putting a '\' in front of the '!' but it doesn't work. Anyone have any ideas on the proper syntax?


try -resize {$max_X}x{$max_Y}!
edit: you still may need to escape the ! using the advice from the other answer


I don't ever remember having to escape an exclamation point, but this may help you:

http://php.net/manual/en/function.escapeshellcmd.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜