<?PHP
$bad = array('html', 'FileType', 'IsColor', 'MimeType', 'SectionsFound', 'YCbCrPositioning', 1, 2);
#$bad = array('html', 'FileType', 'IsColor', 'MimeType', 'SectionsFound', 'YCbCrPositioning');
$url = '';
$i = '';
$width = 0;
$exif = array();
function input($str) {
echo $str." ";
return trim(fgets(STDIN));
}
$url = 'http://upload.wikimedia.org/wikipedia/commons/2/23/Lake_mapourika_NZ.jpeg';
$file = basename($url).'.exif';
$f = fopen($file, 'w');
echo "Downloading ".$file."... ";
if (is_file($url)) $i = file_get_contents($url);
else {
$c = curl_init($url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
$i = curl_exec($c);
if (!$i) {
echo curl_error($c).PHP_EOL;
die();
}
}
if (!$i) die("bad image input.".PHP_EOL);
else echo "done.".PHP_EOL;
fwrite($f, $i);
fclose($f);
if (($itype = exif_imagetype($file)) !== IMAGETYPE_JPEG or $itype === IMAGETYPE_TIFF_II or $itype == IMAGETYPE_TIFF_MM) {
die("Image file type invalid for exif data.".PHP_EOL);
}
$exif = exif_read_data($file);
if (!$exif) die("Image file contained no exif data.".PHP_EOL);
array_walk_recursive($exif, function($v, $k) use (&$width) {
if (strlen($k) > $width) $width = strlen($k);
});
array_walk_recursive($exif, function($v, $k) use ($width, $bad) {
if (preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $v) == '') {
$hex = array();
$v = str_split($v);
array_walk($v,
function($v, $k) use (&$hex) {
$hex[$k] = dechex(ord($v));
}
);
$v = 'HEX[ '.implode(" ", $hex).' ]';
}
else if (is_int($v)) $v = 'INT[ '.$v.' ]';
else $v = 'STRING[ '.$v.' ]';
$lim = 90;
if (strlen($v) > $lim) $v = substr($v, 0, $lim-10).' ... '.substr($v, strlen($v)-5);
if (preg_match('/Thumbnail\..+/i', $k) > 0) return;
if (!in_array($k, $bad) and $v !== '') echo $k.str_repeat(' ', $width-strlen($k)).' => '.$v.PHP_EOL;
});
unlink($file);
?>
preferences:
38.89 ms | 402 KiB | 5 Q