PHP-GD库-分类整理

转载自:http://www.cnblogs.com/silvester/articles/1694677.html

图像信息:
gd_info             取得当前安装的 GD 库的信息
imagetypes            返回当前 PHP 版本所支持的图像类型
image_type_to_extension     取得图像类型的文件后缀
image_type_to_mime_type     取得 图像类型的 MIME 类型
getimagesize             取得图像大小
imagesx             取得图像宽度
imagesy             取得图像高度
imageistruecolor        检查图像是否为真彩色图像

新建/载入图像:
imagecreate — 新建一个基于调色板的图像
imagecreatefromgd2 — 从 GD2 文件或 URL 新建一图像
imagecreatefromgd2part — 从给定的 GD2 文件或 URL 中的部分新建一图像
imagecreatefromgd — 从 GD 文件或 URL 新建一图像
imagecreatefromgif — 从 GIF 文件或 URL 新建一图像
imagecreatefromjpeg — 从 JPEG 文件或 URL 新建一图像
imagecreatefrompng — 从 PNG 文件或 URL 新建一图像
imagecreatefromstring — 从字符串中的图像流新建一图像
imagecreatefromwbmp — 从 WBMP 文件或 URL 新建一图像
imagecreatefromxbm — 从 XBM 文件或 URL 新建一图像
imagecreatefromxpm — 从 XPM 文件或 URL 新建一图像
imagecreatetruecolor — 新建一个真彩色图像

输出图像:
image2wbmp            以 WBMP 格式将图像输出到浏览器或文件
imagegd2            将 GD2 图像输出到浏览器或文件
imagegd                将 GD 图像输出到浏览器或文件
imagegif            以 GIF 格式将图像输出到浏览器或文件
imagewbmp            以 WBMP 格式将图像输出到浏览器或文件
imagexbm            将 XBM 图像输出到浏览器或文件
imagejpeg            以 JPEG 格式将图像输出到浏览器或文件
imagepng            以 PNG 格式将图像输出到浏览器或文件

杂项相关:
imagealphablending        设定图像的混色模式
imageantialias            是否使用抗锯齿(antialias)功能
imageinterlace            激活或禁止隔行扫描
imagegammacorrect        对 GD 图像应用 gamma 修正
iptcembed            将二进制 IPTC 数据嵌入到一幅 JPEG 图像中
iptcparse            将二进制 IPTC http://www.iptc.org/ 块解析为单个标记
imagesavealpha            设置标记以在保存 PNG 图像时保存完整的 alpha 通道信息(与单一透明色相反)

图形相关:
imagearc            画椭圆弧
imageconvolution        用系数 div 和 offset 申请一个 3x3 的卷积矩阵
imagedashedline            画一虚线
imageellipse            画一个椭圆
imagerectangle            画一个矩形
imagefilledarc            画一椭圆弧且填充
imagefilledellipse        画一椭圆并填充
imagefilledpolygon        画一多边形并填充
imagefilledrectangle        画一矩形并填充
imagesetbrush            设定画线用的画笔图像
imagesetpixel            画一个单一像素
imagesetstyle            设定画线的风格
imagesetthickness        设定画线的宽度
imagepolygon            画一个多边形
imageline            画一条线段

字符/字体相关:
imagechar            水平地画一个字符
imagecharup            垂直地画一个字符
imagestring            水平地画一行字符串
imagestringup             垂直地画一行字符串
imagepsbbox            给出一个使用 PostScript Type1 字体的文本方框
imagepsencodefont        改变字体中的字符编码矢量
imagepsextendfont        扩充或精简字体
imagepsfreefont            释放一个 PostScript Type 1 字体所占用的内存
imagepsloadfont            从文件中加载一个 PostScript Type 1 字体
imagepsslantfont        倾斜某字体
imagepstext            用 PostScript Type1 字体把文本字符串画在图像上
imagettfbbox            取得使用 TrueType 字体的文本的范围
imagettftext            用 TrueType 字体向图像写入文本
imageftbbox            给出一个使用 FreeType 2 字体的文本框
imagefttext            使用 FreeType 2 字体将文本写入图像
imagefontheight            取得字体高度
imagefontwidth            取得字体宽度
imageloadfont            载入一新字体

颜色相关:
imagecolorallocate        为一幅图像分配颜色
imagecolorallocatealpha        为一幅图像分配颜色 + alpha
imagecolorat            取得某像素的颜色索引值
imagecolorclosest        取得与指定的颜色最接近的颜色的索引值取得某像素的颜色索引值
imagecolorclosestalpha        取得与指定的颜色加透明度最接近的颜色
imagecolorclosesthwb        取得与给定颜色最接近的色度的黑白色的索引
imagecolordeallocate        取消图像颜色的分配
imagecolorexact            取得指定颜色的索引值
imagecolorexactalpha        取得指定的颜色加透明度的索引值
imagecolormatch            使一个图像中调色板版本的颜色与真彩色版本更能匹配
imagepalettecopy        将调色板从一幅图像拷贝到另一幅
imagecolorresolve        取得指定颜色的索引值或有可能得到的最接近的替代值
imagecolorresolvealpha        取得指定颜色 + alpha 的索引值或有可能得到的最接近的替代值
imagecolorset            给指定调色板索引设定颜色
imagecolorsforindex        取得某索引的颜色
imagecolorstotal        取得一幅图像的调色板中颜色的数目
imagecolortransparent        将某个颜色定义为透明色

图像操作:
imagecopy            拷贝图像的一部分
imagecopymerge            拷贝并合并图像的一部分
imagecopymergegray        用灰度拷贝并合并图像的一部分
imagecopyresampled        重采样拷贝部分图像并调整大小
imagecopyresized        拷贝部分图像并调整大小
imagerotate            用给定角度旋转图像
jpeg2wbmp            将 JPEG 图像文件转换为 WBMP 图像文件
png2wbmp            将 PNG 图像文件转换为 WBMP 图像文件
imagedestroy            销毁一图像

图像处理:
imagefilter            对图像使用过滤器
imagelayereffect        设定 alpha 混色标志以使用绑定的 libgd 分层效果
imagetruecolortopalette        将真彩色图像转换为调色板图像
imagefill            区域填充
imagesettile            设定用于填充的贴图
imagefilltoborder        区域填充到指定颜色的边界为止
imagegrabscreen            捕获屏幕
imagegrabwindow            捕获屏幕(略复杂)


自己写的生成长微博的方法:

function autowrap($fontsize, $angle, $fontface, $string, $width) {
    // 这几个变量分别是 字体大小, 角度, 字体名称, 字符串, 预设宽度
    $content = "";
    // 将字符串拆分成一个个单字 保存到数组 letter 中
    for ($i=0;$i<mb_strlen($string);$i++) {
        $letter[] = mb_substr($string, $i, 1);
    }
    foreach ($letter as $l) {
        $teststr = $content." ".$l;
        $testbox = imagettfbbox($fontsize, $angle, $fontface, $teststr);
        // 判断拼接后的字符串是否超过预设的宽度
        if (($testbox[2] > $width) && ($content !== "")) {
            $content .= "\n";
        }
        $content .= $l;
    }
    return $content;
}

function getLongWeibo()
{
    /**
     * 创建第一张图片
     */
    //字体大小
    $fontSize = 15;
    //字体类型,本例为宋体
    $font ="c:/windows/fonts/simsun.ttc";
    //创建一个长为500高为80的空白图片
    // $img = imagecreate(500, 500); // 使用该方法合成图片可能导致颜色失真
    $size = 500;
    $img = imagecreatetruecolor($size, $size);

    //给背景分配颜色
    $back = imagecolorallocate($img, 255, 255, 255);
    //设置边框颜色
    $border = imagecolorallocate($img, 0, 0, 0);
    imagefilledrectangle($img, 0, 0, $size - 1, $size - 1, $back);
    //设置字体颜色
    $black = imagecolorallocate($img, 0xff, 0xcc, 0xcc);
    //显示的文字
    $text = "Hello world试试 水水水水水水水水水水水水水HHHHHHHHHHHHHHHH!";
    $text = autowrap($fontSize, 0, $font, $text, $size-20);
    // $text = iconv("gbk","utf-8", $text);
    // imagestring($img, $fontSize, 0, 0, $text, $black);
    //将ttf文字写到图片中
    imagettftext($img, $fontSize, 0, 0, 20, $black, $font, $text);

    /**
     * 创建第二张图片
     */
    $filename = 'test2.jpg';
    $percent = 1;
    // Get new sizes
    list($width, $height) = getimagesize($filename);
    $newwidth = $width * $percent;
    $newheight = $height * $percent;
    $img2 = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);
    // Resize
    imagecopyresized($img2, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

    // imagecopymerge($img, $img2, 0, 80, 0, 0, imagesx($img), imagesy($img2), 100); // 在合并图片的时候可能会出现黑色背景等问题
    imagecopyresampled($img, $img2, 0, 80, 0, 0, $newwidth, $newheight, $width, $height);

    $imageName = 'test3.jpg';
    //发送头信息(将图片显示在浏览器中时使用,否则会有乱码)
    // header('Content-Type: image/jpeg');
    //输出图片,输出到指定路径$imageName,没有$imageName参数时将会显示在浏览器中
    $flag = imagejpeg($img, $imageName);
    imagedestroy($img);
    if($flag)
    {
        return $imageName;
    }
    else
    {
        return '';
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值