zoukankan      html  css  js  c++  java
  • GD库

    一、GD库 之GD扩展的引入

    在windos下,php.ini里,去掉php_gd2.dll前的';',引入gd2扩展 在linux下,需要编译时加上gd支持

    可以用gd_info()函数打印gd支持信息

    print_r(gd_info());

    二、GD库 之图片处理典型流程

    1:造画布(或读入一幅图作画布)

    2:造颜料

    3:利用颜料在画布上写字或填充颜色或画形状

    4:输出/生成图片

    5:销毁画布

    //创建画布
    $im = imagecreatetruecolor(200, 100);
    //颜料
    $bg = imagecolorallocate($im , 100, 100, 100);
    //填充图片
    imagefill($im, 0, 0, $bg);
    //生成图片
    imagepng($im, './first.png')

    三、GD库 之图片的坐标

    坐标以图片左上角为原点

    以像素为单位

    如果给x,y轴参数,一般都是x在前,y在后 (x,y)确定一个点

    2个点确定一个矩形 左上角点+宽度+高度确定一个矩形

    四、GD库 之创建画布函数

    resource imagecreatetruecolor ( int $x_size , int $y_size )

    创建x像素宽,y像素高的图片资源

    resource imagecreatefromgif ( string $filename )

    通过读取一幅gif图片作为图片资源

    resource imagecreatefromjpeg ( string $filename )

    通过读取一幅jpg图片作为图片资源

    resource imagecreatefrompng ( string $filename )

    通过读取一幅png图片作为图片资源

    五、GD库 之造颜料的函数

    int imagecolorallocate ( resource $image , int $red , int $green , int $blue )

    六、GD库 之获取图片信息函数

    nt imagesx ( resource $image ):获得图像宽度(像素)

    int imagesy ( resource $image ) :获得图像高度(像素)

    七、GD库 之在图片上写字

    bool imagestring :往图片上写一串字符(无法换行)

    ( resource $image , int $font , int $x , int $y , string $s , int $col )

    bool imagechar : 往图片上写一个字符

    ( resource $image , int $font , int $x , int $y , string $c , int $color )

    bool imagecharup 往图片片竖着写一个字符

    ( resource $image , int $font , int $x , int $y , string $c , int $color )

    八、GD库 之画图形函数

    imageline — 画一条线段

    imagerectangle — 画矩形

    imageellipse — 画一个椭圆

    imagefilledrectangle — 画一矩形并填充

    imagefilledellipse — 画一椭圆并填充

    imagefilledarc — 画一椭圆弧且填充

    imagefilledpolygon — 画一多边形并填充

    imagefill — 区域填充

    九、GD库 之复制图片函数

    bool imagecopy :复制图片某一部分到另外一图片上去

    ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )

    bool imagecopymerge :同上,但多了"透明"选项

    ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )

    十、GD库 之缩略图片函数

    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 )

    十一、GD库 之如何写中文

    TrueType 字体向图像写入文本

    array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

    十二、GD库 之销毁画布

    bool imagedestroy ( resource $image )

    : 销毁图像资源

    十三、GD库 之生成验证码

    创建画布(imagecreatetruecolor)

    往图片写字(imagestring)

    形成图片(image[jpeg|png|gif])

    销毁画布(imagedestroy)

    十四、GD库 之生成缩略图

    读取图片,形成资源(imagecreatefrom***)

    创建缩略画布(imagecreatetruecolor)

    复制图片资源(imagecopyresampled)

    形成图片(image[jpeg|png|gif])

    销毁画布(imagedestroy)

    十五、GD库 之加水印

     读取大图,形成资源(imagecreatefrom***)

    读取水印图片,(同上) 复制图片资源(imagecopymerge)

    形成图片(image[jpeg|png|gif])

    销毁画布(imagedestroy)

  • 相关阅读:
    openssl生成公钥私钥对 加解密
    boost replace_if replace_all_regex_copy用法
    PS 图像滤镜— — USM 锐化
    使用boost库生成 随机数 随机字符串
    改动Android设备信息,如改动手机型号为iPhone7黄金土豪版!
    验证(Verification)与确认(Validation)的差别
    Spring-SpringMVC-Hibernate整合
    全面整理的C++面试题
    Metropolis Hasting算法
    捕捉到来自宇宙深空的神奇X-射线信号
  • 原文地址:https://www.cnblogs.com/suihui/p/3237697.html
Copyright © 2011-2022 走看看