0

如何制作像这样的图像?我只是想学习如何使用 GD 库获得这样的输出,谢谢你们的帮助..

在此处输入图像描述

4

2 回答 2

0

这是一个例子:

header('Content-Type: image/png'); // setting the content-type

$file   = "yourimage.png";
$image  = imagecreatefrompng($file); // creating the image
$font   = "YourFont.ttf";
$size   = 15; //pixels
$color  = imagecolorallocate($image, 255, 255, 255); //white color
$text   = "Your text here"

imagettftext($image, 15, 0, 20, 40, $color, $font, $code); // adding the text

imagepng($image); // outputting the image

更多见imagettftext()

编辑:使用多个示例imagettftext()

header('Content-Type: image/png'); // setting the content-type

$file   = "yourimage.png";
$image  = imagecreatefrompng($file); // creating the image
$font   = "YourFont.ttf";
$size   = 15; //pixels
$color  = imagecolorallocate($image, 255, 255, 255); //white color
$text       = "Your text here"

imagettftext($image, 15, 0, 20, 40, $color, $font, $code); // adding the text

$text = "Text 2";
imagettftext($image, 15, 0, 25, 45, $color, $font, $code); // adding the text

$text = "Text 3";
imagettftext($image, 15, 0, 30, 50, $color, $font, $code); // adding the text

imagepng($image); // outputting the image
于 2012-07-04T17:22:10.810 回答
0

这是你的代码,你可以很容易地在谷歌上找到它。

<?php
    header ("Content-type: image/png");
    $string = "your text"; // Change this text
    $font = 4; // try changing this as well
    $width = imagefontwidth($font) * strlen($string) ;
    $height = imagefontheight($font) ;
    $im = imagecreatefrompng("/path/to/yourimagefile");
    $x = imagesx($im) - $width ;
    $y = imagesy($im) - $height;
    $backgroundColor = imagecolorallocate ($im, 255, 255, 255);
    $textColor = imagecolorallocate ($im, 0, 0,0);
    imagestring ($im, $font, $x, $y,  $string, $textColor);
    imagepng($im);
?>
于 2012-07-04T17:22:55.840 回答