4

このコードを使用すると、テキストから画像を作成できますが、1行で

function writetext($image_path,$imgdestpath,$x,$y,$angle,$text,$font,$fontsize) {
      $image=imagecreatefromjpeg("$image_path");
      $height = imageSY($image);
      $width = imageSX($image);
      $color = imagecolorallocate($image,0,0,0);
      $textwidth = $width;
      imageTTFtext($image,$fontsize,$angle,$x,$y,$color,$font, $text );
      ImageJPEG($image,$imgdestpath);
}

この画像を複数行の段落で作成する方法を教えてください。

4

2 に答える 2

7

各行について、たとえば、$yの新しい値で呼び出される新しいimageTTFtext関数が必要です。

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non nunc lectus.     Curabitur hendrerit bibendum enim dignissim tempus. Suspendisse non ipsum auctor metus consectetur eleifend. Fusce cursus ullamcorper sem nec ultricies. Aliquam erat volutpat. Vivamus massa justo, pharetra et sodales quis, rhoncus in ligula. Integer dolor velit, ultrices in iaculis nec, viverra ut nunc.';

// Break it up into pieces 125 characters long
$lines = explode('|', wordwrap($text, 115, '|'));

// Starting Y position
$y = 513;

// Loop through the lines and place them on the image
foreach ($lines as $line)
{
imagettftext($image, $font_size, 0, 50, $y, $font_color, $font, $line);

// Increment Y so the next line is below the previous line
$y += 23;
}

ソース

于 2012-12-30T11:37:26.420 に答える
0
function writeonimage(){ 

// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('wp-content/themes/ibestquotes/images/background.jpg');

// Allocate A Color For The Text
$white = imagecolorallocate($jpg_image, 255, 255, 255);

// Set Path to Font File
$font_path = 'wp-content/themes/ibestquotes/fonts/arial-italic.ttf';

// Set Text to Be Printed On Image
$text = get_the_title($_REQUEST['did']);

// Break it up into pieces 25 characters long
$lines = explode('|', wordwrap($text, 25, '|'));

// Starting Y position
$y = 100;

// Loop through the lines and place them on the image
foreach ($lines as $line)
{
imagettftext($jpg_image, 20, 0, 40, $y, $white, $font_path, $line);

// Increment Y so the next line is below the previous line
$y += 40;
}

// Send Image to Browser but we are using download image
//imagejpeg($jpg_image,'wp-content/themes/ibestquotes/name.jpg');


header("Content-type: image/jpeg");  
header("Cache-Control: no-store, no-cache");  
header('Content-Disposition: attachment; filename="avatar.jpg"');
imagejpeg($jpg_image);

// Clear Memory
imagedestroy($jpg_image); 
}


//This code is working on 
http://ibestquotes.com/?t=d&did=56
于 2018-05-03T17:13:15.523 に答える