• php中图像处理的常用函数


    1.imagecreate()函数

    imagecreate()函数是基于一个调色板的画布。

    <?php 
        $im = imagecreate(200,80);                //创建一个宽200,高80的画布。
        $white = imagecolorallocate($im,225,35,180);     //设置画布的背景颜色
        imagegif($im);                       //输出像素
    ?>

    注:imagecreate()函数的单位为像素。

    2.imageTTFText()函数

    语法:

    array ImageTTFText(int $im, int $size, int $angle, int $x, int $y, int $color, string $fontfile, string $text);

    imageTTFText()函数共有8个参数,且这8个参数是缺一不可的。$im是指照片等画布资源;$size是字体的大小,在GD1中单位是像素,在GD2中是磅(point),现在一般都是用GD2了;angle是指旋转角度,需要说明有两点:一是角度单位是度而不是弧度,二是旋转的中心点就是参数$x,$y;$x,$y被绘制字符串的第一个字符的基线点,单位是像素;$color是字体的颜色;$fontfile是字体;$text 要渲染的字符串。

    返回值: 数组

    函数种类: 图形处理

    <?php 
        header("content-type:image/jpeg");
        $im = imagecreatefromjpeg("images/1.jpg");
        $textcolor = imagecolorallocate($im,56,73,136);
        $fnt = "c:/windows/fonts/simhei.ttf";
        $motto = iconv("gb2312","utf-8","Banana");
        imageTTFText($im,220,0,480,340,$textcolor,$fnt,$motto);
        imagejpeg($im);
        imagedestroy($im);
    ?>

    在上面的代码中,$im指载入的图片,220是字体的大小,0是文字的水平方向,480、340是文字的坐标值,$textcolor是文字的颜色,$fnt是字体的样式,$motto是照片文字。

     3.getimagesize()函数
    getimagesize()函数主要用于获取图像的大小及相关信息,成功则返回一个数组,失败则返回false 。
    语法:  
    array getimagesize(string filename);  

    例子:

    <?php  
        array = getimagesize("images/flower_1.jpg");  
        print_r($array);  
     ?>  

    其结果为:

    在结果中,[0]是图像的宽度单位像素,

    [1]是图像的高度,单位是像素,

    [2]是图像的类型,返回的是数字:1=>GIF, 2=>JPG, 3=>PNG, 4=>SWF, 5=>PSD, 6=>BMP, 7=>TIFF(intel byte order), 8=>TIFF(motorola byte order), 9=>JPC, 10=>JP2, 11=>JPX, 12=>JB2, 13=>SWC, 14=>IFF, 15=>WBMP, 16=>XBM,

    [3]给出的是一个宽度和高度的字符串,可直接用于HTML的<image>标签,

    [bits]是图像的每种颜色的位数,是二进制格式,

    [channels]是图形的通道值,RGB图像默认是3,

    [mime]是图像的MIME信息,此信息可用来在HTTP Content-type头信息中发送正确的信息。

    4.imagedestroy()函数

    图像处理完成后,使用imagedestroy()函数销毁图像资源释放内存

    语法:

    bool   imagedestroy(resource image);

       

  • 相关阅读:
    推送
    XPath
    XML
    在xcode 6.4 环境下写的demo 在xode7 环境下 网络请求有问题
    SVN 搭建
    翻译
    iOS面试题积累
    安卓扁平化之路专题(三)Android 5.0新特性
    Android @SuppressLint @TargetApi 总结
    Android_support_v4,Android_support_v7,Android_support_v13区别
  • 原文地址:https://www.cnblogs.com/xu2shuang97664/p/4911357.html
Copyright © 2020-2023  润新知