• Welcome to Journal web site.

我是 PHP 程序员

- 开发无止境 -

Next
Prev

php把文字写到图片生成_RemixGdc的博客_php文字生成图片

Data: 2013-12-23 18:03:54Form: JournalClick: 12

php把文字写到图片生成
php把文字写到图片生成_RemixGdc的博客-CSDN博客_php文字生成图片
public function createImg($result, $string){
    $backgroundPath = '背景图路径';
    
    $img = imagecreatefromjpeg($backgroundPath);   //背景图

    //设置字体颜色
    $black = imagecolorallocate($img, 0, 0, 0);

    //字体大小
    $size = 20;
    if(strlen($string) > 24){
        $size = 18;
    }
    //字体
    $font = "assets/fonts/msyhbd.ttf";

    //将ttf文字写到图片中
    imagettftext($img, $size, 0, 108, 502, $black, $font, $string);

    $filePathDir = '生成路径';
    if (!is_dir($filePathDir)) {
        mkdir($filePathDir, 0777, true);
    }

    $filePath   = $filePathDir.time().rand(0,999).'.jpg';
    imagejpeg($img,$filePath);
    return $filePath;
}
Name:
<提交>