• PHP生成带中文的图片


    imagettftext() 函数是 PHP 中的一个内置函数,用于使用 TrueType 字体将文本写入图像。

    句法:

    数组imagettftext(资源$image,float $size,float $angle,
              int $x,int $y,int $color,string $fontfile,string $text)
    参数:此函数接受上述八个参数,如下所述:

    $image:它指定要处理的图像。
    $size:它指定要使用的字体大小,以磅为单位。
    $angle:它以度为单位指定角度。
    $x:指定 x 坐标。
    $y:它指定 y 坐标。
    $color:它指定文本所需颜色的索引。
    $fontfile:它指定要使用的字体。
    $text:它指定要写入的文本。
    返回值:此函数在成功时返回一个数组。

    下面的示例说明了PHP 中的imagettftext() 函数。

    1. <?php
    2. // set up image
    3. $im = ImageCreateTrueColor(200, 100);
    4. $black = ImageColorAllocate ($im, 0, 0, 0);
    5. $white = ImageColorAllocate ($im, 255, 255, 255);
    6. $wenben = "阿酷tony简体中文标题";
    7. ImageFill($im, 0, 0, $black);
    8. //ImageLine($im, 0, 0, 200, 200, $white);
    9. $font = "msyh.ttf";
    10. imagettftext($im, 14, 0, 20, 40, $white , $font, $wenben);
    11. // output image
    12. Header ('Content-type: image/png');
    13. ImagePng($im);
    14. // clean up
    15. ImageDestroy($im);
    16. ?>


     

    1. $bgbgimg='bg.png';
    2. $bgObj=imagecreatefrompng($bgbgimg);
    3. $bg_width=imagesx($bgObj);
    4. $bg_height=imagesy($bgObj);
    5. $bgObj_bg=imagecreatetruecolor($bg_width,$bg_height);
    6. imagecopy($bgObj_bg,$bgObj,0,0,0,0,$bg_width,$bg_height);
    7. $imgpath="test4.png";
    8. $imgObj = imagecreatefrompng($imgpath);
    9. $wh = getimagesize($imgpath);
    10. $imgwidth=intval($wh[0]);
    11. $imgheight=intval($wh[1]);
    12. /**
    13. * $dst_image:目标图连接资源
    14. * $src_image:源图连接资源
    15. * $dst_x:目标图 X 坐标点。 以图片左上角为源点,源图要画在目标图的开始坐标x
    16. * $dst_y:目标图 Y 坐标点。 以图片左上角为源点,源图要画在目标图的开始坐标Y
    17. * $src_x:源图 X坐标点。 以图片左上角为源点,将源图从X位置开始的部分画在目标图上
    18. * $src_y:源图 y坐标点。 以图片左上角为源点,将源图从Y位置开始的部分画在目标图上
    19. * $dst_w:目标图宽度 在目标图上画的宽度
    20. * $dst_h:目标图高度 在目标图上画的高度
    21. * $src_w:源图宽度 要画在目标图上的宽度
    22. * $src_h:源图高度 要画在目标图上的高度
    23. * 例如:目标图为空白 400*400,源图为200*200,下面表示将源图从100*100的位置开始截取50*50的内容在目标图100*100的位置开始画,画的宽度是30*30
    24. * imagecopyresampled($bgObj_bg,$imgObj,100,100,100,100,30,30,50,50);
    25. */
    26. imagecopyresampled($bgObj_bg,$imgObj,100,100,100,100,30,30,50,50);
    27. //输出图片
    28. imagepng($bgObj_bg,'img/real.jpg',9);

    参考: 

    PHP: imagettftext - Manual

  • 相关阅读:
    ST 2.0 霍尔FOC 的相关难点总结
    leetcode day11
    Maestro实践
    Spring Framework :WebClient 取代 RestTemplate
    css常用样式 盒子实体化三属性
    javaweb医院科室管理系统springboot
    LCR 052.递增顺序搜索树
    前端登录退出:处理Token问题(获取、缓存、失效处理)以及代码实现
    校园网页设计成品 学校班级网页制作模板 dreamweaver网页作业 简单网页课程成品 大学生静态HTML网页源码
    如何实现MongoDB数据的快速迁移?
  • 原文地址:https://blog.csdn.net/ffffffff8/article/details/133303741