您的位置:首页 > 编程语言 > PHP开发

PHP极其强大的图片处理库Grafika详细教程(3):图像属性处理

2018-03-08 10:27 1066 查看
接上文:

《1、图像基本处理》
《2、图像特效处理模块》
《3、图像属性处理》
《4、图形绘制》
该文章主要写grafika的图像属性处理功能,共7个方法

1、图片格式化为二进制格式输出

该方法的作用是打开一张图片,然后格式化为二进制数据,直接输出到浏览器,而不是传统的src显示图片。其有一个参数,你可以自定义输出图片的格式,比如png啥的我们这里打开图片,输出为png当然你还是要告诉浏览器你需要输出的类型是图片
header('Content-type: image/png');
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, 'yanying-smaller.jpg' );
header('Content-type: image/png'); // Tell the browser we're sending a png image
$image->blob('PNG');



2、获取图片当前使用的处理库
使用方法可以获取处理当前图片,grafika使用了什么库,是
gd
还是
Imagick
该方法不在
editor
里面,而是直接在
$image
里面,没有任何参数
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, 'yanying-smaller.jpg' );
$result = $image->getCore();
var_dump($result); // resource(12, gd)

3、获取图片高度

我们图片高度为213px
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, 'yanying-smaller.jpg' );
$result = $image->getHeight();
var_dump($result); // int 213

4、获取图片宽度

我们图片宽度为319px
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, 'yanying-smaller.jpg' );
$result = $image->getWidth();
var_dump($result); // int 319

5、获取图片名称

图片名称为当前文件名
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, 'yanying-smaller.jpg' );
$result = $image->getImageFile();
var_dump($result); // string 'yanying-smaller.jpg' (length=19)

6、获取图片类型

这里我们发现是jpg的
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, 'yanying-smaller.jpg' );
$result = $image->getType();
var_dump($result); // string 'JPEG' (length=4)

7、判断图片是否是动态图片,比如gif

我们这张图片是jpg的,所以不是动态图片,返回值为bool类型,true或者false
use Grafika\Grafika;
$editor = Grafika::createEditor();
$editor->open( $image, 'yanying-smaller.jpg' );
$result = $image->isAnimated();
var_dump($result); // boolean false
苏喜武 PHP工程师
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  图片处理 php Grafika