PHP getimagesize()返回哪种文件类型? [英] What kind of file types does PHP getimagesize() return?
问题描述
有人知道PHP的getimagesize()函数返回的第三个值的所有可能结果吗?下面的代码示例将返回:
Does anyone know all the possible results for the 3rd value returned from PHP's getimagesize() function? Example this code below will return:
-
$imageinfo['2'] = 2;
用于jpg
图像, -
$imageinfo['2'] = 3;
用于png
图片, -
$imageinfo['2'] = 0;
用于显示gif
图像.
$imageinfo['2'] = 2;
for ajpg
image,$imageinfo['2'] = 3;
for apng
image,$imageinfo['2'] = 0;
for agif
image.
上面的数字可能不正确,但您明白了.
The numbers might not be correct above but you get the idea.
我无法在php.net或其他任何地方找到第3个值的所有可能结果的列表.
I can't find on php.net or anywhere else a list of all possible results for the 3rd value.
$imageinfo = getimagesize($imageurl);
$image_type = $imageinfo['2'];
推荐答案
执行此操作:
print_r(get_defined_constants());
然后查找以IMAGETYPE_为前缀的常量.在我的PHP 5.3安装中,我得到了以下值:
And then look for constants prefixed with IMAGETYPE_. On my PHP 5.3 installation I got these values:
[IMAGETYPE_GIF] => 1
[IMAGETYPE_JPEG] => 2
[IMAGETYPE_PNG] => 3
[IMAGETYPE_SWF] => 4
[IMAGETYPE_PSD] => 5
[IMAGETYPE_BMP] => 6
[IMAGETYPE_TIFF_II] => 7
[IMAGETYPE_TIFF_MM] => 8
[IMAGETYPE_JPC] => 9
[IMAGETYPE_JP2] => 10
[IMAGETYPE_JPX] => 11
[IMAGETYPE_JB2] => 12
[IMAGETYPE_SWC] => 13
[IMAGETYPE_IFF] => 14
[IMAGETYPE_WBMP] => 15
[IMAGETYPE_JPEG2000] => 9
[IMAGETYPE_XBM] => 16
[IMAGETYPE_ICO] => 17
[IMAGETYPE_UNKNOWN] => 0
[IMAGETYPE_COUNT] => 18
如您所见,Flash SWF被视为图像,实际上getimagesize()
能够读取SWF对象的宽度和高度.对我来说,当我第一次发现它时似乎很好奇,这就是为什么在这里提到它.
As you can see Flash SWF are considered images, and actually getimagesize()
is able to read the width and height of a SWF object. To me it seemed like a curiosity when I first discovered it, that's why mentioned it here.
这篇关于PHP getimagesize()返回哪种文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!