【问题标题】:Change fonts in convering text to image in php在php中将文本转换为图像时更改字体
【发布时间】:2014-12-13 13:48:27
【问题描述】:

我想更改以下代码中的字体...

header("Content-type: image/png");
$text = $_POST['wtr'];
$font = 'fonts/arial.ttf';
$im = @imagecreate(90, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, 0, 0, 0);
imagestring($im, 1, 5, 5, $text, $text_color);
imagepng($im);
imagedestroy($im);    

此代码用于工作并将我的文本转换为图像。

更新:

如何设置背景图片。

【问题讨论】:

  • 我检查了 '$font_width = imagefontwidth(36);'但不工作。字体大小仍然保持不变..
  • 我将 '$font = 'fonts/arial.ttf'' 更改为 '$font = 'fonts/Arial.ttf';'它工作....

标签: php image text watermark


【解决方案1】:

字体大小是imagestring的第二个参数,大小为1-5。所以,例如:

imagestring($im, 1, 5, 5, $text, $text_color); // size 1

imagestring($im, 2, 5, 5, $text, $text_color); // size 2

// etc.

【讨论】:

    【解决方案2】:
        $name="vikram";
        header( "Content-type: image/png" );
        $my_img = imagecreate( 400, 300 );
        $background = imagecolorallocate( $my_img, 255,255, 255 );
        $text_colour = imagecolorallocate( $my_img, 120, 120, 120);
        $font='arial.ttf';
        imagettftext($my_img,40,5,100,200,$text_colour,$font,$name); 
        imagesetthickness ( $my_img, 5 );   
        imagepng('vikram.png');
        imagecolordeallocate( $line_color );
        imagecolordeallocate( $text_color );
        imagecolordeallocate( $background );
        imagedestroy( $my_img );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-10
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      相关资源
      最近更新 更多