ScotlandPHP

image_type_to_mime_type

(PHP 4 >= 4.3.0, PHP 5)

image_type_to_mime_typeGet Mime-Type for image-type returned by getimagesize, exif_read_data, exif_thumbnail, exif_imagetype

Description

string image_type_to_mime_type ( int $imagetype )

The image_type_to_mime_type() function will determine the Mime-Type for an IMAGETYPE constant.

Parameters

imagetype

One of the IMAGETYPE_XXX constants.

Return Values

The returned values are as follows

Returned values Constants
imagetype Returned value
IMAGETYPE_GIF image/gif
IMAGETYPE_JPEG image/jpeg
IMAGETYPE_PNG image/png
IMAGETYPE_SWF application/x-shockwave-flash
IMAGETYPE_PSD image/psd
IMAGETYPE_BMP image/bmp
IMAGETYPE_TIFF_II (intel byte order) image/tiff
IMAGETYPE_TIFF_MM (motorola byte order) image/tiff
IMAGETYPE_JPC application/octet-stream
IMAGETYPE_JP2 image/jp2
IMAGETYPE_JPX application/octet-stream
IMAGETYPE_JB2 application/octet-stream
IMAGETYPE_SWC application/x-shockwave-flash
IMAGETYPE_IFF image/iff
IMAGETYPE_WBMP image/vnd.wap.wbmp
IMAGETYPE_XBM image/xbm
IMAGETYPE_ICO image/vnd.microsoft.icon

Examples

Example #1 image_type_to_mime_type() example

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

Notes

Note:

This function does not require the GD image library.

See Also

add a note add a note

User Contributed Notes 3 notes

up
3
slegersjohn at gmail dot com
3 years ago
If you are working with Images only and you need mime type (e.g. for headers), then this is a fast and reliable technique:

<?php
$file
= 'path/to/image.jpg';
$image_mime = image_type_to_mime_type(exif_imagetype($file));
?>

It will output true image mime type even if you rename your image file.
up
2
benshelock at gmail dot com
8 years ago
I was looking to detect the format of images, Im not suIf if this is etr valign="middle"> alns.eico"te typsiableme. even i $file = 'path/to/image.jpg' ="php.gif- Retrino ocumpe-stypecmime-type ="php.gif:08"n>$image_ mime = ="memn class="default">image_type_to_mime_type$file));
?>; even i $file s.g.ch ));
n>$file
[.jpg'
$image]) { $file image_ image_ cual/.jpg'$image: $file image_ image_ image_ image_ ">&o/.jpg' r /><="m">$image; $file image_ image_ image_ image_ nextk; $file image_ image_ cual/.jpg'$image: $file image_ image_ image_ image_ ">&o/.jpg' r />$image; $file image_ image_ image_ image_ nextk; $file image_ image_ cual/.jpg'">$image: $file image_ image_ image_ image_ ">&o/.jpg' r /><2'>">$image; $file image_ image_ image_ image_ nextk; $file image_ image_ cual/.jpg'$image: $file image_ image_ image_ image_ ">&o/.jpg' r />$image; $file image_ image_ image_ image_ nextk; $file } mime =iv>

up
3 34365">down
3 years ago
I was looking to detect the format of imagMapeft"> numIf i> hp
s = array($file image_ image_ gn="left"> =v> "="m",$file image_ image_ gn="left">div> =v> "jpg",$file image_ image_ gn="left">PN> =v> "2'>",$file image_ image_ gn="left">SW> =v> "swm",$file image_ image_ gn="left">PSD =v> "2sd",$file image_ image_ gn="left">BMP =v> "bmp",$file image_ image_ gn="left"> < =v> "n="m",$file image_ image_ gn="left"> MM =v> "n="m",$file image_ image_ gn="left">JPC =v> "jpc",$file image_ image_ gn="left">JP2 =v> "jp2",$file image_ image_ gn="left">JPX =v> "jpx",$file image_ image_ gn="left">JB2 =v> "jb2",$file image_ image_ gn="left">SWC =v> "swc",$file image_ image_ gn="left">/p> =v> "="m",$file image_ image_ gn="left">WBMP =v> "wbmp",$file image_ image_ gn="left">XBM =v> "xbm",$file image_ image_ gn="left">/CO =v> "=co"$file );>

add a note add a note

User Contributed="clear> ss="na> t" s >
"refft.iccccccccccccccccccccc"function" rel="rdfd-ss="exif_tgo "refft.iccccccccccccccccccccc"function" rel="rdfs-seeAlso">getimagos=age "refft.iccccccccccccccccccccc"function" rel="rdaquo; image_type_to_extensioago(​ro(​pe_to_exts="keywo​rd">(​ro(​pe_to_ext cort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo; image_tystylesheet" typgo(​ro(​pan><​rd">s="keywo​rd">(​ro(​pan><​rd"> cort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo; "refft.iccccccccccccccccccccc"function" rel="rdaquo;alphefaun='/manuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;ane_toiasanuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;arcanuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;onteanuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;onteu "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> go s="keywo> idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> alphe go alphes="keywo> alpheidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> go s="keywo> idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e>f="/utextensioagof="/utexts="keywo>f="/utextidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;e>pyensioagopys="keywo>pyidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;e>pymerguow" v gopymergus="keywo>pymerguidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;e>pymergugrayensioagopymergugrays="keywo>pymergugrayidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;e>pyrese>pyrese>pyrese> "refft.iccccccccccccccccccccc"function" rel="rdaquo;e>pyresizpdensioagopyresizpds="keywo>pyresizpdidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> go s="keywore> idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mgd2 go s="mgd2s="keywore> s="mgd2idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mgd206 l.php. go s="mgd206 ls="keywore> s="mgd206 lidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mgd.php. go s="mgds="keywore> s="mgdidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mgif.php. go s="mgifs="keywore> s="mgif:08"t.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mn="m.php. go s="mn="m"="keywore> s="mn="mid8"t.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mp/manuaapgo s="mp/m"="keywore> s="mp/midort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ore> s="mass="kanuaapgo s="mass="key"keywere> s="mass="kidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ore> s="m s="m ey"keywere> s="mn="midort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mxbm s="mxbm"y"keywere> s="m="midort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> s="mxpm s="mxpm"y"keywere> s="m=pmidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;ere> ur io> ur io> ur io> "refft.iccccccccccccccccccccc"function" rel="rdaquo; fores"y"keyw foresidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo; e1145yensioago "refft.iccccccccccccccccccccc"function" rel="rdaquo;ellips>"y"keywellips>idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;fill.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;fillw frcanuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;fillw ellips>"y"keywfillw ellips>idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;filledpolygxtensioago "refft.iccccccccccccccccccccc"function" rel="rdaquo;filled.imaangl>"y"keywfillw .imaangl>idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;filltob">"y"keywfilltob">idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;filti>"y"keywfilti>idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;font "refft.iccccccccccccccccccccc"function" rel="rdaquo;font/smal "refft.iccccccccccccccccccccc"function" rel="rdaquo;ftbbo2.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;ft href='/. go
    <"keywft>
"refft.iccccccccccccccccccccc"function" rel="rdaquo;gammac/drect go<"keywgammac/drectidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;gd2 go "refft.iccccccccccccccccccccc"function" rel="rdaquo;gd.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;gif.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;grabsereetensioago "refft.iccccccccccccccccccccc"function" rel="rdaquo;grabdd> <:08"t.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;acterlac>s="keywacterlac>:08"t.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;asur io> "refft.iccccccccccccccccccccc"function" rel="rdaquo;n="m.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;layectifect go "refft.iccccccccccccccccccccc"function" rel="rdaquo;l/a>"y"keywidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;loadfont "refft.iccccccccccccccccccccc"function" rel="rdaquo;palet>pyensioagopy"y"keywpalet>pyidort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;p"kanuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;polygxtensioago "refft.iccccccccccccccccccccc"function" rel="rdaquo;psbbo2.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;psen "refft.iccccccccccccccccccccc"function" rel="rdaquo;psee_todfont "refft.iccccccccccccccccccccc"function" rel="rdaquo;psfreefont "refft.iccccccccccccccccccccc"function" rel="rdaquo;psloadfont "refft.iccccccccccccccccccccc"function" rel="rdaquo;psslantfont "refft.iccccccccccccccccccccc"function" rel="rdaquo;ps href='/. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;.imaangl>"y"keyw.imaangl>idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;rot> go "y"keyw.ot> idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdaquo;sasualphe go "refft.iccccccccccccccccccccc"function" rel="rdaquo;setbrusl "refft.iccccccccccccccccccccc"function" rel="rdaquo;setpixel.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;set> "refft.iccccccccccccccccccccc"function" rel="rdaquo;setthicknessanuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;setti/c.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;sss="kanuaapgo "refft.iccccccccccccccccccccc"function" rel="rdaquo;ass="ku "refft.iccccccccccccccccccccc"function" rel="rdaquo;s2.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;syensioago "refft.iccccccccccccccccccccc"function" rel="rdaquo;ur io> "refft.iccccccccccccccccccccc"function" rel="rdaquo;utfbbo2.php. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;utf href='/. go "refft.iccccccccccccccccccccc"function" rel="rdaquo;rd">sanuaapgosned value "refft.iccccccccccccccccccccc"function" rel="rdaquo; "refft.iccccccccccccccccccccc"function" rel="rdaquo;xbm "refft.iccccccccccccccccccccc"function" rel="rdaptc "refft.iccccccccccccccccccccc"function" rel="rdaptcpars>"y"ptcpars>idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdn="m n="m idort.php?bcccccccccccccccccc"/Help "refft.iccccccccccccccccccccc"function" rel="rdpnm pnm idort.php?bcccccccccccccccccc"/Help"refft.-function.imaow-fluidl>"refft.-er">"refft.icpyrspanC>pyrspan &o>py; 2001-2017 The PHP Groumidor"/HelpMy PHP-typidor"/HelpC>v acnidor"/Helpsanuaa>Other PHP-typ sit>sidor"/HelpMirror sit>sidor"/HelpPrivacy policyidor"/Help
hcr"ptvspande">hcr"ptvspande">hcr"ptvspande">hcr"ptvspande">hcr"ptvspande">hcr"ptvspande">"40">smal"To Toptenote"/"keyws/to-topt='12'>"ributass=div cl