美文网首页
PHP---GD库

PHP---GD库

作者: 大菜鸟呀 | 来源:发表于2018-08-18 13:49 被阅读0次

    基本画图步骤:

    <?php
    //1、创建画布
    $img=imagecreatetruecolor(300, 200);
    //2、创建颜色
    $bcak=imagecolorallocate($img, 0, 255, 0);
    //3、填充画布
    imagefill($img, 0, 0, $bcak);
    //4、输出最终图像或保存最终图像
    header('content-type:image/jpeg');
    imagejpeg($img,);//输出图像
    imagejpeg($img,'jin.jpg'); //保存图像
    //5、释放画布资源
    imagedestroy($img);
     ?>
    

    绘制图像的方法:

    绘制图像的方法:
    绘制一个像素点:imagesetpixel(image, x, y, color)
    绘制一条线:imageline(image, x1, y1, x2, y2, color);
    绘制一个矩形:imagerectangle(image, x1, y1, x2, y2, color);
    绘制一个矩形并填充:imagefilledrectangle(image, x1, y1, x2, y2, color);
    
    绘制一个多边形:imagepolygon(image, points, num_points, color)
    绘制一个多边形并填充:imagefilledpolygon(image, points, num_points, color)
    
    绘制一个椭圆:imageellipse(image, cx, cy, width, height, color)
    绘制一个椭圆并填充:imagefilledellipse(image, cx, cy, width, height, color)
    
    绘制一个椭圆弧,并填充:imagefilledarc(image, cx, cy, width, height, start, end, color, style)
     
    
    水平地画一行字符串:imagestring(image, font, x, y, string, color)
    垂直地画一行字符串:imagestringup(image, font, x, y, string, color)
    
    水平地画一个字符:imagechar(image, font, x, y, c, color)
    垂直地画一个字符:imagecharup(image, font, x, y, c, color)
    
    用truetype字符向图像画一个字符串:imagettftext(image, size, angle(角度), x, y, color, fontfile, text)
    

    图片裁切和缩放

    <?PHP
    $img1=imagecreatefromjpeg(filename);
    $img2=imagecreatetruecolor(150, 100);
    imagecopyresampled(dst_image, src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, )
    
    dst_image:目标图片
    src_image:原图片
    
    dst_x、dst_y:
    
    src_x, src_y:
    
    dst_w, dst_h:
    
    src_w, src_h:
    ?>
    

    相关文章

      网友评论

          本文标题:PHP---GD库

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