PHP图片处理库Grafika详细教程(3):图像属性处理
2023-03-09 22:09:19 时间
该文章是接着上篇文章,《PHP极其强大的图片处理库Grafika详细教程(2):图像特效处理模块》,由于grafika功能太多,所以分开写,其他的点击这里
该文章主要写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
相关文章
- 新增 – 多个 Private Marketplace 目录
- GuardDuty 可视化安全管理
- 06 python编程
- Amazon Lex 推出增强的控制台体验和全新的 V2 API
- 搭载 AWS Graviton 2 处理器的 Amazon EC2 M6g、C6g 以及 R6g 实例,现已在光环新网科技公司运营的 AWS 中国(北京)区域及西云数据运营的 AWS 中国(宁夏)区域正式上线
- 在AWS EKS上发布容器服务(下)
- 在 AWS EKS 平台上发布 K8S 服务(上)
- 探索和体验 Graviton2 高性价比
- 新增功能 – AWS Transfer Family 支持 Amazon Elastic File System
- 在中国区构建自动、弹性、安全的多账号体系——账号自动创建和初始化
- Python optparse模块
- Spring Cloud 的云原生迁移 – AWS 上的混合部署架构(下篇)
- Spring Cloud 的云原生迁移 – AWS 上的混合部署架构(上篇)
- 新功能 – AWS Systems Manager 整合了应用程序管理
- python rpc讲解
- AWS CloudShell – 命令行访问 AWS 资源
- AWS Systems Manager 变更管理器的简介
- Java--128陷阱
- Amazon Location – 为应用程序添加地图和位置感知功能
- 新功能 – AWS Systems Manager 队列管理器