2017-05-28 11 views
0

PHPファイルでimageMagick convertコマンドを使用して、画像にキャプションを追加しています。imageMagick:キャプションボックスを自動サイズ変更する方法は?

これは問題なく動作します。

しかし、キャプションのテキストは長い場合があり、キャプションのテキストが長いと、コードを実行すると一部のテキストが表示されなくなります。

キャプションボックスの内容に基づいてキャプションボックスのサイズを変更する方法はありますか?

これは私が私の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"); 

?> 

答えて

1

ImageMagickの中で、自身のイメージとテキストを作成し、画像の下に追加しますか、それをあなたの画像の上に合成してください。前者は、テキストが画像の幅に収まるようにフォントサイズを選択します。注:私は高さやピンチサイズを指定していませんでした。後者はあなたのポイントサイズと幅(高さなし)を使用し、必要なだけ多くの行にテキストをラップします。しかし、テキスト部分は、使用するテキストの行数によって大きくなります。 Pango:別のオプションです。 http://www.imagemagick.org/Usage/text/を参照してください。私が追加すると、ロゴを使って次の2つの結果が得られます:ImageMagick内部画像。提示私のコメントを使用して

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 

enter image description here

convert logo: \ 
\(-size ${wd}x -background '#f48fb0' -gravity center -fill white -pointsize 30 \ 
caption:'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 output3.png 

enter image description here

+0

私は混乱しています!ロゴは何ですか?どうして私は未定義の変数を得るのですか?wdエラー? input.pngファイルはどこに入っていますか? –

+0

2番目のコードを試してみましたが、何も得られません...エラーも画像もありません! –

+0

コードwd = 'convert logo:-format"%w "info:'はPHP経由でも実行できません。この答えは間違っています!あなたの答えを修正するか、削除してください。 –

0

。 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"); 
?> 

または

<?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"); 
?> 

にスペースはWDの計算のための最初の行で終わる\の後に存在しないことを、あなたがコピーしたときにことを確認し、これを貼り付けます。

または、PHPのgetimagesize()を使用してwd引数を取得するだけです。 http://php.net/manual/en/function.getimagesize.php

関連する問題