0%

Somewhere there are still peoples and herds, but not with us, my brothers: here there are states.

A state? What is that? Well! open now your ears to me, for now I will speak to you about the death of peoples.

阅读全文 »

定义

getimagesize - 获取图片尺寸

语法

1
getimagesize ( string $filename [, array &$imageinfo ] ) : array

返回一个 关联 数组,包含指定图片的相关信息。
$filename 可以是本地也可以是远程图片。
$imageinfo 用于获取更多扩展信息,只支持 JFIF 文件。

返回值

返回数组中最多可以包含7个元素,分别如下:

索引 01分别是宽度和高度;
索引 2是图片的类型,是格式如 IMAGETYPE_XXX 的预定义常量之一,如IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP;
索引 3 是宽高的拼接好的字符串,如height=”yyy” width=”xxx”,方便直接用在img标签里;
mime 是对应的MIME 类型,可用于http头信息,如 header("Content-type: {$size['mime']}");;

channels will be 3 for RGB pictures and 4 for CMYK pictures.
bits is the number of bits for each color.


示例

1
2
3
4
$image = 'https://avatars2.githubusercontent.com/u/646129?s=52&v=4';
$data = getimagesize($image, $info);
print_r($data);
print_r($info);

输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Array
(
[0] => 52
[1] => 52
[2] => 2
[3] => width="52" height="52"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
Array
(
[APP0] => JFIF``
)

总结

一般常用于获取图片宽高,其他信息基本用不到。
名称是image size,但不知道返回的是图片的实际大小还是图片的尺寸,而且既然已经返回这么多信息了,为啥不返回图片的字节大小呢,虽然可以通过其他方式获取,但如果能一步到位岂不更省事。

Zarathustra’s eye had perceived that a certain youth avoided him. And as he walked alone one evening over the hills surrounding the town called “The Pied Cow,” behold, there he found the youth sitting leaning against a tree, and gazing with wearied look into the valley.

阅读全文 »