Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Image Functions : imagetypes

imagetypes

Return the image types supported by this PHP build (PHP 4 >= 4.0.2, PHP 5)
int imagetypes ( )

Example 1027. Checking for PNG support

<?php
if (imagetypes() & IMG_PNG) {
   echo
"PNG Support is enabled";
}
?>

Code Examples / Notes » imagetypes

enyo

Why not use this function?
<?php
function getSupportedImageTypes() {
   $aSupportedTypes = array();
   $aPossibleImageTypeBits = array(
       IMG_GIF=>'GIF',
       IMG_JPG=>'JPG',
       IMG_PNG=>'PNG',
       IMG_WBMP=>'WBMP'
   );
   foreach ($aPossibleImageTypeBits as $iImageTypeBits => $sImageTypeString) {
       if (imagetypes() & $iImageTypeBits) {
           $aSupportedTypes[] = $sImageTypeString;
       }
   }
   return $aSupportedTypes;
}
?>


jaldinger

Please note that if only "GIF Read Support" is enabled, the
IMG_GIF bit will not be returned (at least on my system:
PHP 4.3.0/RH Linux 7.2).
To work around this issue, and also the issue that there is no
function that can tell me what image format a GD resource ID
refers to, I use the following switch statement to map the exif
IMAGETYPE_* constants to the GD IMG_* constants:
switch (exif_imagetype($file['tmp_name'])) {
   case IMAGETYPE_GIF:
       $image_type = IMG_GIF;
       break;
   case IMAGETYPE_JPEG:
       $image_type = IMG_JPG;
       break;
   case IMAGETYPE_PNG:
       $image_type = IMG_PNG;
       break;
   case IMAGETYPE_WBMP:
       $image_type = IMG_WBMP;
       break;
    default:
       $image_type = 0;
       break;
}
store this value together with the image data in a database
and later use the following IF statement to see if I can work
with that image (create a thumbnail, etc...)
if ($image_type & (imagetypes() | IMG_GIF)) {
   return $this->createJpegThumbailFromString($data, 46, 27);
} else {
   return file_get_contents($_SERVER['DOCUMENT_ROOT'] .
       '/gfx/no-thumbnail.jpg');
}
HTH anybody...
Joerg.


thundercrew

Im not a smart man but this seemd to be the simplest code and it worked.
Its at the very top of this directory.
<?php
var_dump(gd_info());
?>
Returned image info and more.
array(11) { ["GD Version"]=> string(27) "bundled (2.0.28 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }


jocke

I wrote this function that returns an array with the supported image types
<?php
function getSupportedImageTypes() {
       $aSupportedTypes = array();
       
       $aPossibleImageTypeBits = array(
               "IMG_GIF",
               "IMG_JPG",
               "IMG_PNG",
               "IMG_WBMP"
           );
           
       foreach ($aPossibleImageTypeBits as $iIndex => $sImageTypeBits) {
           
           $sEval  = "if (";
           $sEval .= "imagetypes() & " . $sImageTypeBits . "";
           $sEval .= ") { return TRUE; } else { return FALSE; }";
           
           if (eval($sEval)) {
               $aSupportedTypes[] = str_replace("IMG_", "", $sImageTypeBits);
           }
       }
       
       return $aSupportedTypes;
   }
?>
Hope that helps someone :)
/Jocke Selin
PS, if you know of a better way that doesn't include eval(), please let me know.


Change Language


Follow Navioo On Twitter
gd_info
getimagesize
image_type_to_extension
image_type_to_mime_type
image2wbmp
imagealphablending
imageantialias
imagearc
imagechar
imagecharup
imagecolorallocate
imagecolorallocatealpha
imagecolorat
imagecolorclosest
imagecolorclosestalpha
imagecolorclosesthwb
imagecolordeallocate
imagecolorexact
imagecolorexactalpha
imagecolormatch
imagecolorresolve
imagecolorresolvealpha
imagecolorset
imagecolorsforindex
imagecolorstotal
imagecolortransparent
imageconvolution
imagecopy
imagecopymerge
imagecopymergegray
imagecopyresampled
imagecopyresized
imagecreate
imagecreatefromgd2
imagecreatefromgd2part
imagecreatefromgd
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromstring
imagecreatefromwbmp
imagecreatefromxbm
imagecreatefromxpm
imagecreatetruecolor
imagedashedline
imagedestroy
imageellipse
imagefill
imagefilledarc
imagefilledellipse
imagefilledpolygon
imagefilledrectangle
imagefilltoborder
imagefilter
imagefontheight
imagefontwidth
imageftbbox
imagefttext
imagegammacorrect
imagegd2
imagegd
imagegif
imagegrabscreen
imagegrabwindow
imageinterlace
imageistruecolor
imagejpeg
imagelayereffect
imageline
imageloadfont
imagepalettecopy
imagepng
imagepolygon
imagepsbbox
imagepsencodefont
imagepsextendfont
imagepsfreefont
imagepsloadfont
imagepsslantfont
imagepstext
imagerectangle
imagerotate
imagesavealpha
imagesetbrush
imagesetpixel
imagesetstyle
imagesetthickness
imagesettile
imagestring
imagestringup
imagesx
imagesy
imagetruecolortopalette
imagettfbbox
imagettftext
imagetypes
imagewbmp
imagexbm
iptcembed
iptcparse
jpeg2wbmp
png2wbmp
eXTReMe Tracker