• 常用的PHP图形处理函数


    1. imagecreatetruecolor()  新建一个真彩色图像
    resource imagecreatetruecolor ( int x_size, int y_size )
    imagecreatetruecolor() 返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的黑色图像。

    2. imagecolorallocate()  为一幅图像分配颜色
    int imagecolorallocate ( resource image, int red, int green, int blue )
    imagecolorallocate() 返回一个标识符,代表了由给定的 RGB 成分组成的颜色。red,green 和 blue 分别是所需要的颜色的红,绿,蓝成分。

    3. imagefill()  区域填充
    bool imagefill ( resource image, int x, int y, int color )
    imagefill() 在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。

    4. imagestring()  水平地画一行字符串
    bool imagestring ( resource image, int font, int x, int y, string s, int col )
    imagestring() 用 col 颜色将字符串 s 画到 image 所代表的图像的 x,y 坐标处(这是字符串左上角坐标,整幅图像的左上角为 0,0)。如果 font 是 1,2,3,4 或 5,则使用内置字体。

    5. imageline()  画一条线段
    bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )
    imageline() 用 color 颜色在图像 image 中从坐标 x1,y1 到 x2,y2(图像左上角为 0, 0)画一条线段。

    6. imagesetpixel()  画一个单一像素
    bool imagesetpixel ( resource image, int x, int y, int color )
    imagesetpixel() 在 image 图像中用 color 颜色在 x,y 坐标(图像左上角为 0,0)上画一个点。

    7. imagettftext()  用 TrueType 字体向图像写入文本
    array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )
    image 图像资源
    size 字体大小
    angle 角度制表示的角度,0 度为从左向右读的文本。更高数值表示逆时针旋转
    x 由 x,y 所表示的坐标定义了第一个字符的基本点(大概是字符的左下角)
    y Y 坐标。它设定了字体基线的位置,不是字符的最底端
    color 颜色索引。使用负的颜色索引值具有关闭防锯齿的效果
    fontfile 是想要使用的 TrueType 字体的路径。
    text 要写入的文本字符串

    8. imagecreatefrompng()  从 PNG 文件或 URL 新建一图像
    resource imagecreatefrompng ( string filename )
    imagecreatefrompng() 返回一图像标识符,代表了从给定的文件名取得的图像。

    9. imagecopyresampled()  重采样拷贝部分图像并调整大小
    bool imagecopyresampled ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )
    imagecopyresampled() 将一幅图像中的一块正方形区域拷贝到另一个图像中,平滑地插入像素值,因此,尤其是,减小了图像的大小而仍然保持了极大的清晰度。如果成功则返回 TRUE,失败则返回 FALSE。

    10. PHP生成简单的邮件图标代码

    header('Content-Type:image/png');
    $img=imagecreatetruecolor(400,200);
    $blue=imagecolorallocate($img,0,102,255);
    $white=imagecolorallocate($img,255,255,255);
    imagefill($img,0,0,$blue);
    imagestring($img,2,130,50,'Emailto:admin@TTinfo.com',$white);
    imageline($img,0,0,400,200,$white);
    imageline($img,0,200,400,0,$white);
    for($i=0;$i<200;$i++){
        imagesetpixel($img,rand(0,400),rand(0,200),$white);
    }
    $font='C:WINDOWSFontsSIMKAI.TTF';
    $text=iconv('utf-8','utf-8','收件人:管理员');
    imagettftext($img,20,0,108,40,$white,$font,$text);
      
    imagepng($img);
    imagedestroy($img);
  • 相关阅读:
    分享
    慕课网-软件测试基础-学习笔记
    向量内积(点乘)和外积(叉乘)概念及几何意义
    使用opencv3+python实现视频运动目标检测
    解决opencv3运行opencv2代码时报错的修改备忘录
    分享
    OpenCV学习笔记
    LeetCode
    LeetCode
    npm安装包很慢
  • 原文地址:https://www.cnblogs.com/sheevy/p/4010674.html
Copyright © 2020-2023  润新知