PHP中Grafika如何实现图像属性处理

发布时间:2021-11-02 11:41:08 作者:小新
来源:亿速云 阅读:95

这篇文章主要为大家展示了“PHP中Grafika如何实现图像属性处理”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“PHP中Grafika如何实现图像属性处理”这篇文章吧。

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');

PHP中Grafika如何实现图像属性处理

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中Grafika如何实现图像属性处理”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

推荐阅读:
  1. PHP 处理图像步骤解析
  2. PHP中图像处理简介

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:怎么理解List的扩容机制

下一篇:如何使用matplotlib中的折线图方法plot()

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》