Created
December 6, 2011 08:50
-
-
Save k-holy/1437431 to your computer and use it in GitHub Desktop.
IMAGETYPE定数と拡張子とmimeTypeの一覧を取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$constants = get_defined_constants(true); | |
$supportedImageType = function($type) { | |
$_type = 0; | |
switch ($type) { | |
case IMAGETYPE_GIF: | |
$_type = IMG_GIF; | |
break; | |
case IMAGETYPE_JPEG: | |
$_type = IMG_JPG; | |
break; | |
case IMAGETYPE_PNG: | |
$_type = IMG_PNG; | |
break; | |
case IMAGETYPE_WBMP: | |
$_type = IMG_WBMP; | |
break; | |
} | |
return (($_type & imagetypes()) !== 0); | |
}; | |
$data = array_fill_keys(array_filter(array_keys($constants['standard']), | |
function($name) { | |
return (strpos($name, 'IMAGETYPE_') === 0); | |
} | |
), null); | |
array_walk($data, function(&$image, $key, $supportedImageType) { | |
$image = new \StdClass(); | |
$image_type = constant($key); | |
$image->constant = $key; | |
$image->imageType = $image_type; | |
$image->supported = $supportedImageType($image_type); | |
$image->extension = image_type_to_extension($image_type, false); | |
$image->mimeType = image_type_to_mime_type($image_type); | |
}, $supportedImageType); | |
include 'image_types.template.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Template; | |
class U | |
{ | |
public static function H($data, $default=null) | |
{ | |
$var = $default; | |
if (isset($data)) { | |
if (is_bool($data)) { | |
$var = ($data) ? 'TRUE' : 'FALSE'; | |
} else { | |
$var = htmlspecialchars($data, ENT_QUOTES, 'UTF-8'); | |
} | |
} | |
return $var; | |
} | |
} | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<style type="text/css"> | |
body {font-family:monospace;} | |
table {border-collapse:collapse; margin:5px 0px;} | |
table * {text-align:left;} | |
caption {font-size:200%;} | |
th, td {padding:2px; border:solid 1px #999999;} | |
</style> | |
</head> | |
<body> | |
<table> | |
<thead> | |
<tr> | |
<th>定数名</th> | |
<th>定数値</th> | |
<th>サポート</th> | |
<th>拡張子</th> | |
<th>MIMEタイプ</th> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach ($data as $image) : ?> | |
<tr> | |
<th><?=U::H($image->constant)?></th> | |
<td><?=U::H($image->imageType)?></td> | |
<td><?=U::H($image->supported)?></td> | |
<td><?=U::H($image->extension)?></td> | |
<td><?=U::H($image->mimeType)?></td> | |
</tr> | |
<?php endforeach ?> | |
</tbody> | |
</table> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$constants = get_defined_constants(true); | |
$supportedImageType = function($type) { | |
$_type = 0; | |
switch ($type) { | |
case IMAGETYPE_GIF: | |
$_type = IMG_GIF; | |
break; | |
case IMAGETYPE_JPEG: | |
$_type = IMG_JPG; | |
break; | |
case IMAGETYPE_PNG: | |
$_type = IMG_PNG; | |
break; | |
case IMAGETYPE_WBMP: | |
$_type = IMG_WBMP; | |
break; | |
} | |
return (($_type & imagetypes()) !== 0); | |
}; | |
$image_types = array_intersect_ukey($constants['standard'], $constants['standard'], | |
function($name1, $name2) { | |
return (strpos($name1, 'IMAGETYPE_') === 0) ? 0 : 1; | |
} | |
); | |
$data = array(); | |
array_walk($image_types, function($image_type, $key, $supportedImageType) use (&$data) { | |
$image = new \stdClass(); | |
$image->constant = $key; | |
$image->imageType = $image_type; | |
$image->supported = $supportedImageType($image_type); | |
$image->extension = image_type_to_extension($image_type, false); | |
$image->mimeType = image_type_to_mime_type($image_type); | |
$data[] = $image; | |
}, $supportedImageType); | |
include 'image_types.template.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment