框架: PHP Laravel 5.5
code
public function waterfall(Request $request)
{
$im = imagecreatetruecolor(500, 500);
$white = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $white); // 填滿白色 (背景)
// 你的字体文件
$font = base_path('resources') . '/fonts/yourfonts.ttf';
$black = imagecolorallocate($im, 51, 51, 51);
$user = '焦糖大瓜子';
$name = '信息敏感,严禁外传';
imagefttext($im, 24, 30, 20, 300, $black, $font, $name);
// $image, $size, $angle, $x, $y, $color, $fontfile, $text, $extrainfo = null
imagefttext($im, 24, 30, 120, 350, $black, $font, $user);
imagecolortransparent($im, $white);
// 设置header
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
}
result

Note:
自动换行可以参考:
https://blog.gxxsite.com/php-image-draw-text-line-auto-cut/
网友评论