2016-10-08 52 views
0

画像:それは私が手紙は、この機能を使用する例である電源が入っていることをたいことだけうまく機能PHP GD縦書きテキスト私はPHPで縦書きテキストに画像を置くしたい

function scrivi($scrivi, $p) { 
    $imgResource = imagecreatefromjpeg($p); 
    $textcolor = imagecolorallocate($imgResource, 255, 255, 255); 
    $fontPath = "st.ttf"; 
    $fontSize = "18"; 
    $rotation = "270"; // counter-clockwise rotation 
    $text = "this is a text"; 
    $textCoords = imagettfbbox($fontSize, $rotation, $fontPath, $text); 
    $x = 36; 
    $y = 36; 
    imagettftext($imgResource, $fontSize, $rotation, $x, $y, $textcolor, $fontPath, $text); 
    unlink($p); 
    imagejpeg($imgResource, $p, 100); 
    imagedestroy($imgResource); 
} 

enter image description here

代わりに私が

enter image description here

たい

アイデアは、あなたが本当にする必要があるすべては、配列、ループそれにテキストを分割された各文字

答えて

0

をラップ、フォントの文字のリーディング+高さyを相殺することができます

function scrivi($p,$text) 
    { 
     $imgResource = imagecreatefromjpeg($p); 
     $textcolor  = imagecolorallocate($imgResource, 255,255, 255); 
     $fontPath  = __DIR__."/st.ttf"; 
     $fontSize  = "18"; 
     $x = 36 ; 
     $y = 36; 
     foreach(str_split($text) as $char) { 
      $textCoords = imagettfbbox($fontSize, 0, $fontPath, $char); 
      imagettftext($imgResource, $fontSize, 0, $x, $y, $textcolor,$fontPath,$char); 
      $y += 24; 
     } 
     unlink($p); 
     imagejpeg($imgResource,$p,100); 
     imagedestroy($imgResource); 
    } 

scrivi('http://imgtops.sourceforge.net/bakeoff/bw.jpg',"Cats are great"); 

enter image description here

(画像クレジット:http://imgtops.sourceforge.net/bakeoff/

はあなたに与えます

+0

あなたの似たような解決策に達しましたが、今では手紙を中央に置くことができる問題が発生しています。 http://imgur.com/a/YVVTR – effeee

+0

それを理解する。私はスクリプトをテストする必要があります。 – Rasclatt

+0

私はすぐに外に出なければなりませんが、それを行うには、最大のキャラクタの幅を取得する必要があります(現在のループの前にループを作成します)。次に、スタッキングループの現在の文字を測定する必要があります。最大の文字と現在の文字を2で割った差が、左にインデントした値になります。それはキャラクターを中心にすべきです。 – Rasclatt

関連する問題