I am trying a run an image magick commands which spans overs two lines for better readability. Will it run OK with PHP exec method? As an example, please have a look at following lines:
我正在尝试运行一个图像magick命令,它跨越两行,以获得更好的可读性。使用PHP exec方法运行OK吗?举个例子,请看以下几行:
exec("convert thumbnail.gif autumn_leaves.png +swap
-gravity center -compose DstOver -composite
border_leaves.gif");
2 个解决方案
#1
1
This is how I write my code now for better readability:
这就是我现在写代码的方式,为了更好的可读性:
$cmd = "thumbnail.gif autumn_leaves.png +swap ".
" -gravity center -compose DstOver -composite ";
exec("convert $cmd border_leaves.gif");
This has an added benifit that if you are using variables in you code you can echo $cmd to view what the actual command is.
这有一个额外的好处,如果你在你的代码中使用变量,你可以echo $cmd来查看实际的命令是什么。
Another thought is if you write your code in blocks you can comment out blocks when fault finding to see where the code goes wrong.
另一个想法是,如果你把代码写在块中,你可以在错误发现的时候注释掉代码块,看看代码哪里出错了。
#2
3
Probably not. Instead of putting the new lines actually in the string, you could use concatenation so it looks like multiple lines but the final string is still one line:
可能不会。而不是把新行放到字符串中,你可以使用连接,这样它看起来就像多行,但最后一个字符串仍然是一行:
exec("convert thumbnail.gif autumn_leaves.png +swap " .
"-gravity center -compose DstOver -composite " .
"border_leaves.gif");
#1
1
This is how I write my code now for better readability:
这就是我现在写代码的方式,为了更好的可读性:
$cmd = "thumbnail.gif autumn_leaves.png +swap ".
" -gravity center -compose DstOver -composite ";
exec("convert $cmd border_leaves.gif");
This has an added benifit that if you are using variables in you code you can echo $cmd to view what the actual command is.
这有一个额外的好处,如果你在你的代码中使用变量,你可以echo $cmd来查看实际的命令是什么。
Another thought is if you write your code in blocks you can comment out blocks when fault finding to see where the code goes wrong.
另一个想法是,如果你把代码写在块中,你可以在错误发现的时候注释掉代码块,看看代码哪里出错了。
#2
3
Probably not. Instead of putting the new lines actually in the string, you could use concatenation so it looks like multiple lines but the final string is still one line:
可能不会。而不是把新行放到字符串中,你可以使用连接,这样它看起来就像多行,但最后一个字符串仍然是一行:
exec("convert thumbnail.gif autumn_leaves.png +swap " .
"-gravity center -compose DstOver -composite " .
"border_leaves.gif");