function GetJpegInfo($file) { $info = array('jpeg' => false, 'filesize' => 0, 'imagedata' => 0, 'appdata' => 0, 'progressive' => false, 'commentsize' => 0, 'comment' => '', 'scans' => 0); $bytes = file_get_contents($file); if ($bytes !== false) { $i = 0; $size = $info['filesize'] = strlen($bytes); while (FindNextMarker($bytes, $size, $i, $marker, $marker_length)) { $marker = bin2hex($marker); if ($marker == 'ffd8') { $info['jpeg'] = true; } elseif ($marker == 'ffc2') { $info['progressive'] = true; } elseif ($marker == 'ffda') { $info['scans']++; } elseif ($marker == 'fffe') { $info['commentsize'] += $marker_length; $info['comment'] = substr($bytes, $i, $marker_length); } elseif (substr($marker, 0, 3) == 'ffe') { $info['appdata'] += $marker_length; } if (substr($marker, 0, 3) == 'ffc' || substr($marker, 0, 3) == 'ffd') { $info['imagedata'] += $marker_length; } $i += $marker_length; } } if (!$info['jpeg']) { $info = false; } return $info; }
function FindNextScan(&$bytes, $size, &$i) { $found = false; if ($i < $size) { while (!$found && FindNextMarker($bytes, $size, $i, $marker, $marker_length)) { if (bin2hex($marker) == 'ffda') { $found = true; } $i += $marker_length; } if (!$found) { $found = true; $i = $size; } } return $found; }