在 php 中将融合文本中的字体更改为图像


Change fonts in convering text to image in php

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

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

这段代码正在工作并将我的文本转换为图像。

更新:

如何设置背景图像。

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

imagestring($im, 1, 5, 5, $text, $text_color); // size 1
imagestring($im, 2, 5, 5, $text, $text_color); // size 2
// etc.
    $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 );