Php imageMagick:如何自动调整标题框的大小?
我在Php imageMagick:如何自动调整标题框的大小?,php,imagemagick,Php,Imagemagick,我在PHP文件中使用imageMagick convert命令向图像添加标题 这个很好用 但是,标题文本有时可能很长,如果标题文本很长,当我运行代码时,一些文本会丢失 有没有办法根据标题框的内容调整其大小 这是我从php文件运行的代码: <?php shell_exec("convert input.png \ -gravity Southwest -background '#f48fb0' -splice 0x44 \ -pointsize
PHP
文件中使用imageMagick convert
命令向图像添加标题
这个很好用
但是,标题文本有时可能很长,如果标题文本很长,当我运行代码时,一些文本会丢失
有没有办法根据标题框的内容调整其大小
这是我从php文件运行的代码:
<?php
shell_exec("convert input.png \
-gravity Southwest -background '#f48fb0' -splice 0x44 \
-pointsize 30 -fill white -annotate +10+4 'This is a long caption texts that I need to place in the image caption... blah blah blah blah... This is a long caption texts that I need to place in the image caption... blah blah blah blah... ' output.png");
?>
您可以使用label:或caption:在ImageMagick中将文本创建为自己的图像,并附加到图像底部或在图像底部合成文本。前者会选择一种字体大小,使文本适合图像的宽度。注:我没有指定高度或品脱大小。后者将使用您的点大小和宽度(无高度),并根据需要将文本换行。但是,它使用的文本行数增加了文本部分的高度。盘古:是另一种选择。看见如果我附加,那么我使用logo:ImageMagick internal image获得这两个结果
wd=`convert logo: -format "%w" info:`
convert logo: \
\( -size ${wd}x -background '#f48fb0' -gravity center -fill white \
label:'This is a long caption texts that I need to place in the image caption... blah blah blah blah... This is a long caption texts that I need to place in the image caption... blah blah blah blah... ' \) \
-append output2.png
使用我的评论。我已经修改了我的代码以使用PHP。这应该行得通。如果不允许exec,您可以尝试shell_exec
<?php
$wd = exec("convert input.png -format '%w' info:");
exec("convert logo: \( -size ${wd}x -background '#f48fb0' -gravity center -fill white label:'This is a long caption texts that I need to place in the image caption... blah blah blah blah... This is a long caption texts that I need to place in the image caption... blah blah blah blah... ' \) -append output.png");
?>
我糊涂了!什么是标志?为什么我会得到未定义的变量:wd error?input.png文件从何而来?尝试了第二个代码,但我什么也没有得到。。。没有错误,没有图像!代码wd=转换徽标:-格式“%w”信息:
也不能通过PHP运行。这个答案全错了!请修改或删除您的答案。我的代码只是unix ImageMagick命令行代码。wd行获取图像宽度并将其放入变量wd中。您可以用PHP代码替换它。获得图像宽度后,可以在PHP exec()中调用其他两个命令行$wd=exec(“转换徽标:-格式“%w”信息:”);logo:image是ImageMagick内部的特殊图像。您可以将logo:替换为您自己的图像,格式为imagename.suffix,例如input.png
<?php
$wd = exec("convert input.png -format '%w' info:");
exec("convert logo: \( -size ${wd}x -background '#f48fb0' -gravity center -fill white label:'This is a long caption texts that I need to place in the image caption... blah blah blah blah... This is a long caption texts that I need to place in the image caption... blah blah blah blah... ' \) -append output.png");
?>
<?php
exec("wd=`convert input.png -format '%w' info:` \
convert input.png \( -size ${wd}x -background '#f48fb0' -gravity center -fill white label:'This is a long caption texts that I need to place in the image caption... blah blah blah blah... This is a long caption texts that I need to place in the image caption... blah blah blah blah... ' \) -append output.png");
?>