function parseCanon($block, &$result, $seek, $globalOffset) { $place = 0; //current place if ($result['Endien'] == "Intel") { $intel = 1; } else { $intel = 0; } $model = $result['IFD0']['Model']; //Get number of tags (2 bytes) $num = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $num = intel2Moto($num); } $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num); //loop thru all tags Each field is 12 bytes for ($i = 0; $i < hexdec($num); $i++) { //2 byte tag $tag = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $tag = intel2Moto($tag); } $tag_name = lookup_Canon_tag($tag); //2 byte type $type = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $type = intel2Moto($type); } lookup_type($type, $size); //4 byte count of number of data units $count = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $count = intel2Moto($count); } $bytesofdata = validSize($size * hexdec($count)); if ($bytesofdata <= 0) { return; //if this value is 0 or less then we have read all the tags we can } //4 byte value of data or pointer to data $value = substr($block, $place, 4); $place += 4; if ($bytesofdata <= 4) { $data = substr($value, 0, $bytesofdata); } else { $value = bin2hex($value); if ($intel == 1) { $value = intel2Moto($value); } $v = fseek($seek, $globalOffset + hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file if (isset($GLOBALS['exiferFileSize'])) { $exiferFileSize = $GLOBALS['exiferFileSize']; } else { $exiferFileSize = 0; } if ($v == 0 && $bytesofdata < $exiferFileSize) { $data = fread($seek, $bytesofdata); } else { if ($v == -1) { $result['Errors'] = $result['Errors']++; $data = ''; } else { $data = ''; } } } $result['SubIFD']['MakerNote'][$tag_name] = ''; // insure the index exists $formated_data = formatCanonData($type, $tag, $intel, $data, $result, $result['SubIFD']['MakerNote'][$tag_name]); if ($result['VerboseOutput'] == 1) { //$result['SubIFD']['MakerNote'][$tag_name] = $formated_data; if ($type == "URATIONAL" || $type == "SRATIONAL" || $type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") { $data = bin2hex($data); if ($intel == 1) { $data = intel2Moto($data); } } $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata; } else { //$result['SubIFD']['MakerNote'][$tag_name] = $formated_data; } } }
function parseSanyo($block, &$result, $seek, $globalOffset) { if ($result['Endien'] == "Intel") { $intel = 1; } else { $intel = 0; } $model = $result['IFD0']['Model']; $place = 8; //current place $offset = 8; //Get number of tags (2 bytes) $num = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $num = intel2Moto($num); } $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num); //loop thru all tags Each field is 12 bytes for ($i = 0; $i < hexdec($num); $i++) { //2 byte tag $tag = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $tag = intel2Moto($tag); } $tag_name = lookup_Sanyo_tag($tag); //2 byte type $type = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $type = intel2Moto($type); } lookup_type($type, $size); //4 byte count of number of data units $count = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $count = intel2Moto($count); } $bytesofdata = validSize($size * hexdec($count)); //4 byte value of data or pointer to data $value = substr($block, $place, 4); $place += 4; if ($bytesofdata <= 4) { $data = substr($value, 0, $bytesofdata); } else { $value = bin2hex($value); if ($intel == 1) { $value = intel2Moto($value); } $v = fseek($seek, $globalOffset + hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file if ($tag != 0) { $data = fread($seek, $bytesofdata); } else { if ($v == -1) { $result['Errors'] = $result['Errors']++; } } } $formated_data = formatSanyoData($type, $tag, $intel, $data); if ($result['VerboseOutput'] == 1) { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; if ($type == "URATIONAL" || $type == "SRATIONAL" || $type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") { $data = bin2hex($data); if ($intel == 1) { $data = intel2Moto($data); } } $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata; } else { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; } } }
function parseFujifilm($block, &$result) { //if($result['Endien']=="Intel") $intel=1; //else $intel=0; $intel = 1; $model = $result['IFD0']['Model']; $place = 8; //current place $offset = 8; $num = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $num = intel2Moto($num); } $result['SubIFD']['MakerNote']['Offset'] = hexdec($num); //Get number of tags (2 bytes) $num = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $num = intel2Moto($num); } $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num); //loop thru all tags Each field is 12 bytes for ($i = 0; $i < hexdec($num); $i++) { //2 byte tag $tag = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $tag = intel2Moto($tag); } $tag_name = lookup_Fujifilm_tag($tag); //2 byte type $type = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $type = intel2Moto($type); } lookup_type($type, $size); //4 byte count of number of data units $count = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $count = intel2Moto($count); } $bytesofdata = validSize($size * hexdec($count)); //4 byte value of data or pointer to data $value = substr($block, $place, 4); $place += 4; if ($bytesofdata <= 4) { $data = substr($value, 0, $bytesofdata); } else { $value = bin2hex($value); if ($intel == 1) { $value = intel2Moto($value); } $data = substr($block, hexdec($value) - $offset, $bytesofdata * 2); } $formated_data = formatFujifilmData($type, $tag, $intel, $data); if ($result['VerboseOutput'] == 1) { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; if ($type == "URATIONAL" || $type == "SRATIONAL" || $type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") { $data = bin2hex($data); if ($intel == 1) { $data = intel2Moto($data); } } $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata; } else { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; } } }
//Get Crust Type if (isset($_GET['crust'])) { $crust = $_GET['crust']; if (!validCrust($crust)) { print "<p>There has been an error. Please only select from crusts originally listed.</p>"; $isValid = false; return; } } else { print "<p>Please select your crust type.</p>"; $isValid = false; } //Get Size if (isset($_GET['size'])) { $size = $_GET['size']; if (!validSize($size)) { print "<p>There has been an error. Please only select small, medium, or large.<p>"; $isValid = false; return; } elseif ($size == "none") { print "<p>Please select which size pizza you would like to enjoy today.<p>"; $isValid = false; } } else { print "<p>Please select the size of your pizza.</p>"; $isValid = false; } //Summary if ($isValid) { print "Thank you for your order, {$fname} {$lname}"; print "<p>Method: {$method}</p>";
function parseNikon($block, &$result) { if ($result['Endien'] == "Intel") { $intel = 1; } else { $intel = 0; } $model = $result['IFD0']['Model']; //these 6 models start with "Nikon". Other models dont. if ($model == "E700" || $model == "E800" || $model == "E900" || $model == "E900S" || $model == "E910" || $model == "E950") { $place = 8; //current place $model = 0; //Get number of tags (2 bytes) $num = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $num = intel2Moto($num); } $result['SubIFD']['MakerNote']['MakerNoteNumTags'] = hexdec($num); //loop thru all tags Each field is 12 bytes for ($i = 0; $i < hexdec($num); $i++) { //2 byte tag $tag = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $tag = intel2Moto($tag); } $tag_name = lookup_Nikon_tag($tag, $model); //2 byte type $type = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $type = intel2Moto($type); } lookup_type($type, $size); //4 byte count of number of data units $count = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $count = intel2Moto($count); } $bytesofdata = validSize($size * hexdec($count)); //4 byte value of data or pointer to data $value = substr($block, $place, 4); $place += 4; //if tag is 0002 then its the ASCII value which we know is at 140 so calc offset //THIS HACK ONLY WORKS WITH EARLY NIKON MODELS if ($tag == "0002") { $offset = hexdec($value) - 140; } if ($bytesofdata <= 4) { $data = substr($value, 0, $bytesofdata); } else { $value = bin2hex($value); if ($intel == 1) { $value = intel2Moto($value); } $data = substr($block, hexdec($value) - $offset, $bytesofdata * 2); } $formated_data = formatNikonData($type, $tag, $intel, $model, $data); if ($result['VerboseOutput'] == 1) { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata; } else { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; } } } else { $place = 0; //current place $model = 1; $nikon = substr($block, $place, 8); $place += 8; $endien = substr($block, $place, 4); $place += 4; //2 bytes of 0x002a $tag = bin2hex(substr($block, $place, 2)); $place += 2; //Then 4 bytes of offset to IFD0 (usually 8 which includes all 8 bytes of TIFF header) $offset = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $offset = intel2Moto($offset); } if (hexdec($offset) > 8) { $place += $offset - 8; } //Get number of tags (2 bytes) $num = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $num = intel2Moto($num); } //loop thru all tags Each field is 12 bytes for ($i = 0; $i < hexdec($num); $i++) { //2 byte tag $tag = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $tag = intel2Moto($tag); } $tag_name = lookup_Nikon_tag($tag, $model); //2 byte type $type = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $type = intel2Moto($type); } lookup_type($type, $size); //4 byte count of number of data units $count = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $count = intel2Moto($count); } $bytesofdata = validSize($size * hexdec($count)); //4 byte value of data or pointer to data $value = substr($block, $place, 4); $place += 4; if ($bytesofdata <= 4) { $data = substr($value, 0, $bytesofdata); } else { $value = bin2hex($value); if ($intel == 1) { $value = intel2Moto($value); } $data = substr($block, hexdec($value) + hexdec($offset) + 2, $bytesofdata); } $formated_data = formatNikonData($type, $tag, $intel, $model, $data); if ($result['VerboseOutput'] == 1) { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; if ($type == "URATIONAL" || $type == "SRATIONAL" || $type == "USHORT" || $type == "SSHORT" || $type == "ULONG" || $type == "SLONG" || $type == "FLOAT" || $type == "DOUBLE") { $data = bin2hex($data); if ($intel == 1) { $data = intel2Moto($data); } } $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['RawData'] = $data; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Type'] = $type; $result['SubIFD']['MakerNote'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata; } else { $result['SubIFD']['MakerNote'][$tag_name] = $formated_data; } } } }
function parseGPS($block, &$result, $offset, $seek, $globalOffset) { if ($result['Endien'] == "Intel") { $intel = 1; } else { $intel = 0; } $v = fseek($seek, $globalOffset + $offset); //offsets are from TIFF header which is 12 bytes from the start of the file if ($v == -1) { $result['Errors'] = $result['Errors']++; } $num = bin2hex(fread($seek, 2)); if ($intel == 1) { $num = intel2Moto($num); } $num = hexdec($num); $result['GPS']['NumTags'] = $num; if ($num == 0) { return; } $block = fread($seek, $num * 12); $place = 0; //loop thru all tags Each field is 12 bytes for ($i = 0; $i < $num; $i++) { //2 byte tag $tag = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $tag = intel2Moto($tag); } $tag_name = lookup_GPS_tag($tag); //2 byte datatype $type = bin2hex(substr($block, $place, 2)); $place += 2; if ($intel == 1) { $type = intel2Moto($type); } lookup_type($type, $size); //4 byte number of elements $count = bin2hex(substr($block, $place, 4)); $place += 4; if ($intel == 1) { $count = intel2Moto($count); } $bytesofdata = validSize($size * hexdec($count)); //4 byte value or pointer to value if larger than 4 bytes $value = substr($block, $place, 4); $place += 4; if ($bytesofdata <= 4) { $data = substr($value, 0, $bytesofdata); } else { if (strpos('unknown', $tag_name) !== false || $bytesofdata > 1024) { $result['Errors'] = $result['Errors']++; $data = ''; $type = 'ASCII'; } else { $value = bin2hex($value); if ($intel == 1) { $value = intel2Moto($value); } $v = fseek($seek, $globalOffset + hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file if ($v == 0) { $data = fread($seek, $bytesofdata); } else { $result['Errors'] = $result['Errors']++; $data = ''; $type = 'ASCII'; } } } if ($result['VerboseOutput'] == 1) { $result['GPS'][$tag_name] = formatGPSData($type, $tag, $intel, $data); $result['GPS'][$tag_name . "_Verbose"]['RawData'] = bin2hex($data); $result['GPS'][$tag_name . "_Verbose"]['Type'] = $type; $result['GPS'][$tag_name . "_Verbose"]['Bytes'] = $bytesofdata; } else { $result['GPS'][$tag_name] = formatGPSData($type, $tag, $intel, $data); } } }
function read_entry(&$result, $in, $seek, $intel, $ifd_name, $globalOffset) { if (feof($in)) { // test to make sure we can still read. $result['Errors'] = $result['Errors'] + 1; return; } // 2 byte tag $tag = bin2hex(fread($in, 2)); if ($intel == 1) { $tag = intel2Moto($tag); } $tag_name = lookup_tag($tag); // 2 byte datatype $type = bin2hex(fread($in, 2)); if ($intel == 1) { $type = intel2Moto($type); } lookup_type($type, $size); if (strpos($tag_name, 'unknown:') !== false && strpos($type, 'error:') !== false) { // we have an error $result['Errors'] = $result['Errors'] + 1; return; } // 4 byte number of elements $count = bin2hex(fread($in, 4)); if ($intel == 1) { $count = intel2Moto($count); } $bytesofdata = validSize($size * hexdec($count)); // 4 byte value or pointer to value if larger than 4 bytes $value = fread($in, 4); if ($bytesofdata <= 4) { // if datatype is 4 bytes or less, its the value $data = substr($value, 0, $bytesofdata); } else { if ($bytesofdata < 100000) { // otherwise its a pointer to the value, so lets go get it $value = bin2hex($value); if ($intel == 1) { $value = intel2Moto($value); } $v = fseek($seek, $globalOffset + hexdec($value)); // offsets are from TIFF header which is 12 bytes from the start of the file if ($v == 0) { $data = fread($seek, $bytesofdata); } else { if ($v == -1) { $result['Errors'] = $result['Errors'] + 1; } } } else { // bytesofdata was too big, so the exif had an error $result['Errors'] = $result['Errors'] + 1; return; } } if ($tag_name == 'MakerNote') { // if its a maker tag, we need to parse this specially $make = $result['IFD0']['Make']; if ($result['VerboseOutput'] == 1) { $result[$ifd_name]['MakerNote']['RawData'] = $data; } if (preg_match('/NIKON/i', $make)) { require_once dirname(__FILE__) . '/makers/nikon.php'; parseNikon($data, $result); $result[$ifd_name]['KnownMaker'] = 1; } else { if (preg_match('/OLYMPUS/i', $make)) { require_once dirname(__FILE__) . '/makers/olympus.php'; parseOlympus($data, $result, $seek, $globalOffset); $result[$ifd_name]['KnownMaker'] = 1; } else { if (preg_match('/Canon/i', $make)) { require_once dirname(__FILE__) . '/makers/canon.php'; parseCanon($data, $result, $seek, $globalOffset); $result[$ifd_name]['KnownMaker'] = 1; } else { if (preg_match('/FUJIFILM/i', $make)) { require_once dirname(__FILE__) . '/makers/fujifilm.php'; parseFujifilm($data, $result); $result[$ifd_name]['KnownMaker'] = 1; } else { if (preg_match('/SANYO/i', $make)) { require_once dirname(__FILE__) . '/makers/sanyo.php'; parseSanyo($data, $result, $seek, $globalOffset); $result[$ifd_name]['KnownMaker'] = 1; } else { if (preg_match('/Panasonic/i', $make)) { require_once dirname(__FILE__) . '/makers/panasonic.php'; parsePanasonic($data, $result, $seek, $globalOffset); $result[$ifd_name]['KnownMaker'] = 1; } else { $result[$ifd_name]['KnownMaker'] = 0; } } } } } } } else { if ($tag_name == 'GPSInfoOffset') { require_once dirname(__FILE__) . '/makers/gps.php'; $formated_data = formatData($type, $tag, $intel, $data); $result[$ifd_name]['GPSInfo'] = $formated_data; parseGPS($data, $result, $formated_data, $seek, $globalOffset); } else { // Format the data depending on the type and tag $formated_data = formatData($type, $tag, $intel, $data); $result[$ifd_name][$tag_name] = $formated_data; if ($result['VerboseOutput'] == 1) { if ($type == 'URATIONAL' || $type == 'SRATIONAL' || $type == 'USHORT' || $type == 'SSHORT' || $type == 'ULONG' || $type == 'SLONG' || $type == 'FLOAT' || $type == 'DOUBLE') { $data = bin2hex($data); if ($intel == 1) { $data = intel2Moto($data); } } $result[$ifd_name][$tag_name . '_Verbose']['RawData'] = $data; $result[$ifd_name][$tag_name . '_Verbose']['Type'] = $type; $result[$ifd_name][$tag_name . '_Verbose']['Bytes'] = $bytesofdata; } } } }