画布

作者: 疾风追马 | 来源:发表于2018-06-11 09:39 被阅读8次

    需要条件:要开启php.ini中的php.gd2

    1. 创建画布
      imagecreatetruecolor()
      w 宽度 h 高度
      header('Content-Type: image/jpeg')
    2. 分配颜色
      $color = imagecolorallocate(img,r,g,b)
    3. 填充颜色
      imagefill(img,x,y,color)
    4. 显示画布
      $bg = imagejpeg($img)

    基本图形绘制

    1. 绘制矩形
      imagerectangle(img,x1,y1,x2,y2,color)
    2. 直线
      imageline(img,x1,y1,x2,y2,color)
    3. 字母
      imagestring(img,1-5,x1,y1,str,color)
      只能绘制字母
    4. 绘制汉字
      imagettftext(img,size,angle,x,y,color,font,text)
      x,y为左下角坐标
      font字体
    5. 输出画布
      imagejpeg(img,【,filename】)
      imagepng(img,【,filename】)
      imagegif(img,【,filename】)
      filename省略表示输出到浏览器

    从图片创建画布

    imagecreatefromjpeg
    imagecreatefrompng
    imagecreatefromgif

    1. 获取图片信息
      getimagesize($file)

    注意:

    1.undefined function imagettftext()
    可能是没有装FreeType,curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
    2.如果出错无法显示图片,需要将header注释掉,查看错误信息

    验证码

    1.获取随机字母
    2.绘制到指定区域
    3.将验证码保存到session中,用于验证
    4.将img的src改为验证码地址

    水印

    imagecopymerge()

    缩略图

    imagecopyresampled()

    相关文章

      网友评论

          本文标题:画布

          本文链接:https://www.haomeiwen.com/subject/ashtsftx.html