image_type_to_mime_type

(PHP 4 >= 4.3.0, PHP 5)

image_type_to_mime_type -- 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型

说明

string image_type_to_mime_type ( int imagetype )

image_type_to_mime_type() 函数可以判断一个 IMAGETYPE 常量的 MIME 类型。

例子 1. image_type_to_mime_type (file)

<?php
header
("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG));
?>

返回值如下:

表格 1. 返回值常量

图像类型(imagetype返回值
IMAGETYPE_GIFimage/gif
IMAGETYPE_JPEGimage/jpeg
IMAGETYPE_PNGimage/png
IMAGETYPE_SWFapplication/x-shockwave-flash
IMAGETYPE_PSDimage/psd
IMAGETYPE_BMPimage/bmp
IMAGETYPE_TIFF_II (intel byte order)image/tiff
IMAGETYPE_TIFF_MM (motorola byte order) image/tiff
IMAGETYPE_JPCapplication/octet-stream
IMAGETYPE_JP2image/jp2
IMAGETYPE_JPXapplication/octet-stream
IMAGETYPE_JB2application/octet-stream
IMAGETYPE_SWCapplication/x-shockwave-flash
IMAGETYPE_IFFimage/iff
IMAGETYPE_WBMPimage/vnd.wap.wbmp
IMAGETYPE_XBMimage/xbm

注: 本函数不需要 GD 库。

参见 getimagesize()exif_imagetype()exif_read_data()exif_thumbnail()


add a note add a note User Contributed Notes
Lszl Balaton
16-Jul-2006 05:43
In certain cases, e.g. with using Internet Explore, this function returns with the value "image/pjpeg".

Using exactly the same picture, on Mozilla based browsers this function returns with the value "image/jpeg".

Note the difference "p" before the slash.

I think it is only true with images created by digital camera and transformed by special softwares, e.g. Photoshop.

However, I think, it is worth to pay attention to this small difference.
aidan at php dot net
11-Sep-2004 04:04
This functionality is now implemented in the PEAR package PHP_Compat.

More information about using this function without upgrading your version of PHP can be found on the below link:

http://pear.php.net/package/PHP_Compat