0
我一起使用imagemagick和php来处理一些单词。我首先将一个句子分解成单词,然后准备这些单词作为长命令行参数,我打算通过PHP的exec()命令调用这个参数。我已经仔细检查了这个论点。根据我的知识,所有的角色都可以正确转义,包括单引号和双引号。 exec()函数不起作用,说"The filename, directory name, or volume label syntax is incorrect"
。但是,当我回显$escaped variable
并将回显的字符串分配给php的exec()时,它可以正常工作。PHP的exec()命令不接受执行的有效变量
这里是回馈字符串
exec("convert -background DeepSkyBlue -fill black -font Ultima-Alt-Bold.ttf -pointsize 90 -gravity center -density 90 label:\"SALIVA \" -fill black -font Ultima-Alt-Bold.ttf -pointsize 90 -gravity center -density 90 label:\"USED \" -fill black -font Ultima-Alt-Bold.ttf -pointsize 90 -gravity center -density 90 label:\"AS! \" +append Ulti.png"); // It works
我使用的代码:
$file = 'theboldfont.ttf';
$name = substr($file, 0, 4);
$s = "SALIVA USED AS!";
$words = explode(' ',$s);
$string = '';
foreach ($words as $word)
{
$string .= " " . '-fill black -font ' . $file . ' -pointsize 90 -gravity center -density 90 label:"' . $word . ' "';
}
$command = 'convert -background DeepSkyBlue ' . $string . ' +append ' . $name. '.png';
function w32escapeshellarg($s)
{ return '"' . addcslashes($s, '\\"') . '"'; }
$escaped = w32escapeshellarg($command);
exec($escaped); // It is not working
你看着使用[PHP iMagick图书馆](http://php.net/manual/en/book.imagick.php)?调用本地PHP函数应该比运行'exec()'命令更可靠 – samlev
检查你的php.ini文件是否安装了正确的imagemagick –
@Saurabh,是的,它安装正确。 –