ImageMagick creating thumbnail

梦想的初衷 提交于 2019-12-25 07:48:42

问题


here is code which creats animated text using imagemagick..

$label=$_POST["label"];
$cmd = " -background transparent -font $font -pointsize $size label:$label -stroke black -strokewidth 2 ".
"  \( -clone 0 -tile \"" . $image . "[0]\" -stroke black -strokewidth 2 -gravity center -annotate +0+0 $label \) ".

the above code wokrs fine when i enter "1234" in label field ... but it doe not when i type"12 34" it displays only "12" it is not taking "space" in between charcter ...something needs to be done for "label" variable.. not sure how to fix this.. please help me to resolve this...


回答1:


Put the entire string in double quotes since spaces are not allowed in command line. In the following i enclosed both usages of $label in double-quotes using the \" escape sequence:

$label=$_POST["label"];
$cmd = " -background transparent -font $font -pointsize $size label:\"$label\" -stroke black -strokewidth 2 ".
"  \( -clone 0 -tile \"" . $image . "[0]\" -stroke black -strokewidth 2 -gravity center -annotate +0+0 \"$label\" \) ".



回答2:


Use apostrophes, like in example "Labels over Multiple Lines" at http://www.imagemagick.org/Usage/text/#label

$cmd = " -background transparent -font $font -pointsize $size label:'$label' -stroke black -strokewidth 2 ".



回答3:


My post is editted. See what hakre posted, it's a better answer than mine was.

string escapeshellarg ( string $arg )

Should do the trick, plus it allows you to pass a string directly to the shell function treated as a single safe argument



来源:https://stackoverflow.com/questions/8756110/imagemagick-creating-thumbnail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!