Skip to content

Instantly share code, notes, and snippets.

@k-holy
Created December 6, 2011 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k-holy/1437431 to your computer and use it in GitHub Desktop.
Save k-holy/1437431 to your computer and use it in GitHub Desktop.
IMAGETYPE定数と拡張子とmimeTypeの一覧を取得
<?php
// ワンライナーは挫折しました…。
$imageTypes = array_fill_keys(array_filter(array_keys(get_defined_constants()),
function($name) {
return (strncmp('IMAGETYPE_', $name, 10) === 0);
}
), array());
array_walk($imageTypes, function(&$item, $key, $supported) {
$imageType = constant($key);
$supported = (0 !== ($supported & $imageType));
$item['constant' ] = $key;
$item['imageType'] = $imageType;
$item['supported'] = $supported;
$item['extension'] = image_type_to_extension($imageType, false);
$item['mimeType' ] = image_type_to_mime_type($imageType);
}, imagetypes());
echo '<pre>';
print_r($imageTypes);
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment