日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

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

發布時間:2025/7/14 php 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP极其强大的图片处理库Grafika详细教程(3):图像属性处理 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

該文章是接著上篇文章,《PHP極其強大的圖片處理庫Grafika詳細教程(2):圖像特效處理模塊》,由于grafika功能太多,所以分開寫,其他的點擊這里

《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研發工程師

博客:segmentfault主頁

總結

以上是生活随笔為你收集整理的PHP极其强大的图片处理库Grafika详细教程(3):图像属性处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。