当前位置: 首页 > 科技观察

PHP图像处理库Grafika详细教程(三):图像属性处理

时间:2023-03-12 19:56:32 科技观察

本文是上篇文章《PHP极其强大的图片处理库Grafika详细教程(2):图像特效处理模块》的续篇。由于grafika的功能太多,所以单独写。其他的点这里《1、图像基本处理》《2、图像特效处理模块》《3、图像属性处理》《4、图形绘制》这篇文章主要是写Grafika的图片属性处理函数,一共7个方法。1、该方法的作用是打开一张图片,格式化为二进制数据,直接输出到浏览器,而不是传统的src显示图片。它有一个参数,可以自定义输出图片的格式,比如png,我们这里打开图片,输出的是png,当然你还是要告诉浏览器你需要的输出类型是图片头('Content-type:image/png');useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');header('Content-type:image/png');//告诉浏览器我们正在发送png图像$image->blob('PNG');2.获取图片当前使用的处理库。使用该方法获取并处理当前图像。grafika用的什么库,是gd还是imagick?该方法不在编辑器中,而是直接在$image中,没有参数useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$result=$image->getCore();var_dump($result);//resource(12),gd)3.获取图片高度我们的图片高度是213pxuseGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$result=$image->getHeight();var_dump($result);//int2134,得到图片宽度我们的图片宽度是319pxuseGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$result=$image->getWidth();var_dump($result);//int3195,获取图像名称图像名称为当前文件名useGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$result=$image->getImageFile();var_dump($result);//string'yanying-smaller.jpg'(length=19)6,获取图片类型这里我们发现是useGrafika\Grafika的jpg;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$result=$image->getType();var_dump($result);//string'JPEG'(length=4)7.判断图片是否为动态图片,比如gif,我们的图片是jpg,所以不是动态图片,返回值为bool类型。true或falseuseGrafika\Grafika;$editor=Grafika::createEditor();$editor->open($image,'yanying-smaller.jpg');$result=$image->isAnimated();var_dump($result);//booleanfalse