Exemplo n.º 1
0
Arquivo: exif.php Projeto: anqh/core
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 = $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 = $value;
    } 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;
            }
        }
    }
}
Exemplo n.º 2
0
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);
    //4 byte number of elements
    $count = bin2hex(fread($in, 4));
    if ($intel == 1) {
        $count = intel2Moto($count);
    }
    $bytesofdata = $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 = $value;
    } 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 (eregi("NIKON", $make)) {
            require_once 'makers/nikon.php';
            parseNikon($data, $result);
            $result[$ifd_name]['KnownMaker'] = 1;
        } else {
            if (eregi("OLYMPUS", $make)) {
                require_once 'makers/olympus.php';
                parseOlympus($data, $result, $seek, $globalOffset);
                $result[$ifd_name]['KnownMaker'] = 1;
            } else {
                if (eregi("Canon", $make)) {
                    require_once 'makers/canon.php';
                    parseCanon($data, $result, $seek, $globalOffset);
                    $result[$ifd_name]['KnownMaker'] = 1;
                } else {
                    if (eregi("FUJIFILM", $make)) {
                        require_once 'makers/fujifilm.php';
                        parseFujifilm($data, $result);
                        $result[$ifd_name]['KnownMaker'] = 1;
                    } else {
                        if (eregi("SANYO", $make)) {
                            require_once 'makers/sanyo.php';
                            parseSanyo($data, $result, $seek, $globalOffset);
                            $result[$ifd_name]['KnownMaker'] = 1;
                        } else {
                            $result[$ifd_name]['KnownMaker'] = 0;
                        }
                    }
                }
            }
        }
    } else {
        if ($tag_name == "GPSInfoOffset") {
            require_once '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;
            }
        }
    }
}