Exemplo n.º 1
0
Arquivo: exif.php Projeto: anqh/core
function formatData($type, $tag, $intel, $data)
{
    switch ($type) {
        case 'ASCII':
            if (($pos = strpos($data, chr(0))) !== false) {
                // Search for a null byte and stop there.
                $data = substr($data, 0, $pos);
            }
            if ($tag == '010f') {
                $data = ucwords(strtolower(trim($data)));
            }
            // Format certain kinds of strings nicely (Camera make etc.)
            break;
        case 'URATIONAL':
        case 'SRATIONAL':
            switch ($tag) {
                case '011a':
                    // XResolution
                // XResolution
                case '011b':
                    // YResolution
                    $data = round(unRational($data, $type, $intel)) . ' dots per ResolutionUnit';
                    break;
                case '829a':
                    // Exposure Time
                    $data = formatExposure(unRational($data, $type, $intel));
                    break;
                case '829d':
                    // FNumber
                    $data = 'f/' . unRational($data, $type, $intel);
                    break;
                case '9204':
                    // ExposureBiasValue
                    $data = round(unRational($data, $type, $intel), 2) . ' EV';
                    break;
                case '9205':
                    // ApertureValue
                // ApertureValue
                case '9202':
                    // MaxApertureValue
                    // ApertureValue is given in the APEX Mode. Many thanks to Matthieu Froment for this code
                    // The formula is : Aperture = 2*log2(FNumber) <=> FNumber = e((Aperture.ln(2))/2)
                    $datum = exp(unRational($data, $type, $intel) * log(2) / 2);
                    $data = round($datum, 1);
                    // Focal is given with a precision of 1 digit.
                    $data = 'f/' . $datum;
                    break;
                case '920a':
                    // FocalLength
                    $data = unRational($data, $type, $intel) . ' mm';
                    break;
                case '9201':
                    // ShutterSpeedValue
                    // The ShutterSpeedValue is given in the APEX mode. Many thanks to Matthieu Froment for this code
                    // The formula is : Shutter = - log2(exposureTime) (Appendix C of EXIF spec.)
                    // Where shutter is in APEX, log2(exposure) = ln(exposure)/ln(2)
                    // So final formula is : exposure = exp(-ln(2).shutter)
                    // The formula can be developed : exposure = 1/(exp(ln(2).shutter))
                    $datum = exp(unRational($data, $type, $intel) * log(2));
                    if ($datum != 0) {
                        $datum = 1 / $datum;
                    }
                    $data = formatExposure($datum);
                    break;
                default:
                    $data = unRational($data, $type, $intel);
                    break;
            }
            break;
        case 'USHORT':
        case 'SSHORT':
        case 'ULONG':
        case 'SLONG':
        case 'FLOAT':
        case 'DOUBLE':
            $data = rational($data, $type, $intel);
            switch ($tag) {
                case '0112':
                    // Orientation
                    // Example of how all of these tag formatters should be...
                    switch ($data) {
                        case 0:
                            // not set, presume normal
                        // not set, presume normal
                        case 1:
                            $data = gettext('1: Normal (0 deg)');
                            break;
                        case 2:
                            $data = gettext('2: Mirrored');
                            break;
                        case 3:
                            $data = gettext('3: Upside-down');
                            break;
                        case 4:
                            $data = gettext('4: Upside-down Mirrored');
                            break;
                        case 5:
                            $data = gettext('5: 90 deg CW Mirrored');
                            break;
                        case 6:
                            $data = gettext('6: 90 deg CCW');
                            break;
                        case 7:
                            $data = gettext('7: 90 deg CCW Mirrored');
                            break;
                        case 8:
                            $data = gettext('8: 90 deg CW');
                            break;
                        default:
                            $data = sprintf(gettext('%d: Unknown'), $data);
                            break;
                    }
                    break;
                case '0128':
                    // ResolutionUnit
                // ResolutionUnit
                case 'a210':
                    // FocalPlaneResolutionUnit
                // FocalPlaneResolutionUnit
                case '0128':
                    // ThumbnailResolutionUnit
                    switch ($data) {
                        case 1:
                            $data = gettext('No Unit');
                            break;
                        case 2:
                            $data = gettext('Inch');
                            break;
                        case 3:
                            $data = gettext('Centimeter');
                            break;
                    }
                    break;
                case '0213':
                    // YCbCrPositioning
                    switch ($data) {
                        case 1:
                            $data = gettext('Center of Pixel Array');
                            break;
                        case 2:
                            $data = gettext('Datum Point');
                            break;
                    }
                    break;
                case '8822':
                    // ExposureProgram
                    switch ($data) {
                        case 1:
                            $data = gettext('Manual');
                            break;
                        case 2:
                            $data = gettext('Program');
                            break;
                        case 3:
                            $data = gettext('Aperture Priority');
                            break;
                        case 4:
                            $data = gettext('Shutter Priority');
                            break;
                        case 5:
                            $data = gettext('Program Creative');
                            break;
                        case 6:
                            $data = gettext('Program Action');
                            break;
                        case 7:
                            $data = gettext('Portrait');
                            break;
                        case 8:
                            $data = gettext('Landscape');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                            break;
                    }
                    break;
                case '9207':
                    // MeteringMode
                    switch ($data) {
                        case 1:
                            $data = gettext('Average');
                            break;
                        case 2:
                            $data = gettext('Center Weighted Average');
                            break;
                        case 3:
                            $data = gettext('Spot');
                            break;
                        case 4:
                            $data = gettext('Multi-Spot');
                            break;
                        case 5:
                            $data = gettext('Pattern');
                            break;
                        case 6:
                            $data = gettext('Partial');
                            break;
                        case 255:
                            $data = gettext('Other');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                            break;
                    }
                    break;
                case '9208':
                    // LightSource
                    switch ($data) {
                        case 1:
                            $data = gettext('Daylight');
                            break;
                        case 2:
                            $data = gettext('Fluorescent');
                            break;
                        case 3:
                            $data = gettext('Tungsten');
                            break;
                            // 3 Tungsten (Incandescent light)
                            // 4 Flash
                            // 9 Fine Weather
                        // 3 Tungsten (Incandescent light)
                        // 4 Flash
                        // 9 Fine Weather
                        case 10:
                            $data = gettext('Flash');
                            break;
                            // 10 Cloudy Weather
                            // 11 Shade
                            // 12 Daylight Fluorescent (D 5700 - 7100K)
                            // 13 Day White Fluorescent (N 4600 - 5400K)
                            // 14 Cool White Fluorescent (W 3900 -4500K)
                            // 15 White Fluorescent (WW 3200 - 3700K)
                            // 10 Flash
                        // 10 Cloudy Weather
                        // 11 Shade
                        // 12 Daylight Fluorescent (D 5700 - 7100K)
                        // 13 Day White Fluorescent (N 4600 - 5400K)
                        // 14 Cool White Fluorescent (W 3900 -4500K)
                        // 15 White Fluorescent (WW 3200 - 3700K)
                        // 10 Flash
                        case 17:
                            $data = gettext('Standard Light A');
                            break;
                        case 18:
                            $data = gettext('Standard Light B');
                            break;
                        case 19:
                            $data = gettext('Standard Light C');
                            break;
                        case 20:
                            $data = gettext('D55');
                            break;
                        case 21:
                            $data = gettext('D65');
                            break;
                        case 22:
                            $data = gettext('D75');
                            break;
                        case 23:
                            $data = gettext('D50');
                            break;
                        case 24:
                            $data = gettext('ISO Studio Tungsten');
                            break;
                        case 255:
                            $data = gettext('Other');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                            break;
                    }
                    break;
                case '9209':
                    // Flash
                    switch ($data) {
                        case 0:
                            $data = gettext('No Flash');
                            break;
                        case 1:
                            $data = gettext('Flash');
                            break;
                        case 5:
                            $data = gettext('Flash, strobe return light not detected');
                            break;
                        case 7:
                            $data = gettext('Flash, strobe return light detected');
                            break;
                        case 9:
                            $data = gettext('Compulsory Flash');
                            break;
                        case 13:
                            $data = gettext('Compulsory Flash, Return light not detected');
                            break;
                        case 15:
                            $data = gettext('Compulsory Flash, Return light detected');
                            break;
                        case 16:
                            $data = gettext('No Flash');
                            break;
                        case 24:
                            $data = gettext('No Flash');
                            break;
                        case 25:
                            $data = gettext('Flash, Auto-Mode');
                            break;
                        case 29:
                            $data = gettext('Flash, Auto-Mode, Return light not detected');
                            break;
                        case 31:
                            $data = gettext('Flash, Auto-Mode, Return light detected');
                            break;
                        case 32:
                            $data = gettext('No Flash');
                            break;
                        case 65:
                            $data = gettext('Red Eye');
                            break;
                        case 69:
                            $data = gettext('Red Eye, Return light not detected');
                            break;
                        case 71:
                            $data = gettext('Red Eye, Return light detected');
                            break;
                        case 73:
                            $data = gettext('Red Eye, Compulsory Flash');
                            break;
                        case 77:
                            $data = gettext('Red Eye, Compulsory Flash, Return light not detected');
                            break;
                        case 79:
                            $data = gettext('Red Eye, Compulsory Flash, Return light detected');
                            break;
                        case 89:
                            $data = gettext('Red Eye, Auto-Mode');
                            break;
                        case 93:
                            $data = gettext('Red Eye, Auto-Mode, Return light not detected');
                            break;
                        case 95:
                            $data = gettext('Red Eye, Auto-Mode, Return light detected');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                            break;
                    }
                    break;
                case 'a001':
                    // ColorSpace
                    if ($data == 1) {
                        $data = gettext('sRGB');
                    } else {
                        $data = gettext('Uncalibrated');
                    }
                    break;
                case 'a002':
                    // ExifImageWidth
                // ExifImageWidth
                case 'a003':
                    // ExifImageHeight
                    $data = $data . ' ' . gettext('pixels');
                    break;
                case '0103':
                    // Compression
                    switch ($data) {
                        case 1:
                            $data = gettext('No Compression');
                            break;
                        case 6:
                            $data = gettext('Jpeg Compression');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                            break;
                    }
                    break;
                case 'a217':
                    // SensingMethod
                    switch ($data) {
                        case 1:
                            $data = gettext('Not defined');
                            break;
                        case 2:
                            $data = gettext('One Chip Color Area Sensor');
                            break;
                        case 3:
                            $data = gettext('Two Chip Color Area Sensor');
                            break;
                        case 4:
                            $data = gettext('Three Chip Color Area Sensor');
                            break;
                        case 5:
                            $data = gettext('Color Sequential Area Sensor');
                            break;
                        case 7:
                            $data = gettext('Trilinear Sensor');
                            break;
                        case 8:
                            $data = gettext('Color Sequential Linear Sensor');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                            break;
                    }
                    break;
                case '0106':
                    // PhotometricInterpretation
                    switch ($data) {
                        case 1:
                            $data = gettext('Monochrome');
                            break;
                        case 2:
                            $data = gettext('RGB');
                            break;
                        case 6:
                            $data = gettext('YCbCr');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                            break;
                    }
                    break;
                    //case "a408":	// Contrast
                    //case "a40a":	//Sharpness
                    //	switch($data) {
                    //		case 0: $data="Normal"; break;
                    //		case 1: $data="Soft"; break;
                    //		case 2: $data="Hard"; break;
                    //		default: $data="Unknown"; break;
                    //	}
                    //	break;
                    //case "a409":	// Saturation
                    //	switch($data) {
                    //		case 0: $data="Normal"; break;
                    //		case 1: $data="Low saturation"; break;
                    //		case 2: $data="High saturation"; break;
                    //		default: $data="Unknown"; break;
                    //	}
                    //	break;
                    //case "a402":	// Exposure Mode
                    //	switch($data) {
                    //		case 0: $data="Auto exposure"; break;
                    //		case 1: $data="Manual exposure"; break;
                    //		case 2: $data="Auto bracket"; break;
                    //		default: $data="Unknown"; break;
                    //	}
                    //	break;
            }
            break;
        case 'UNDEFINED':
            switch ($tag) {
                case '9000':
                    // ExifVersion
                // ExifVersion
                case 'a000':
                    // FlashPixVersion
                // FlashPixVersion
                case '0002':
                    // InteroperabilityVersion
                    $data = gettext('version') . ' ' . $data / 100;
                    break;
                case 'a300':
                    // FileSource
                    $data = bin2hex($data);
                    $data = str_replace('00', '', $data);
                    $data = str_replace('03', gettext('Digital Still Camera'), $data);
                    break;
                case 'a301':
                    // SceneType
                    $data = bin2hex($data);
                    $data = str_replace('00', '', $data);
                    $data = str_replace('01', gettext('Directly Photographed'), $data);
                    break;
                case '9101':
                    // ComponentsConfiguration
                    $data = bin2hex($data);
                    $data = str_replace('01', 'Y', $data);
                    $data = str_replace('02', 'Cb', $data);
                    $data = str_replace('03', 'Cr', $data);
                    $data = str_replace('04', 'R', $data);
                    $data = str_replace('05', 'G', $data);
                    $data = str_replace('06', 'B', $data);
                    $data = str_replace('00', '', $data);
                    break;
                    //case "9286":	//UserComment
                    //	$encoding	= rtrim(substr($data, 0, 8));
                    //	$data		= rtrim(substr($data, 8));
                    //	break;
            }
            break;
        default:
            $data = bin2hex($data);
            if ($intel == 1) {
                $data = intel2Moto($data);
            }
            break;
    }
    return $data;
}
Exemplo n.º 2
0
function formatData($type, $tag, $intel, $data)
{
    if ($type == 'ASCII') {
        // Search for a null byte and stop there.
        if (($pos = strpos($data, chr(0))) !== false) {
            $data = substr($data, 0, $pos);
        }
        // Format certain kinds of strings nicely (Camera make etc.)
        if ($tag == '010f') {
            $data = ucwords(strtolower(trim($data)));
        }
    } else {
        if ($type == 'URATIONAL' || $type == 'SRATIONAL') {
            $data = bin2hex($data);
            if ($intel == 1) {
                $data = intel2Moto($data);
            }
            if ($intel == 1) {
                $top = hexdec(substr($data, 8, 8));
            } else {
                $top = hexdec(substr($data, 0, 8));
            }
            // motorola stores them top-bottom
            if ($intel == 1) {
                $bottom = hexdec(substr($data, 0, 8));
            } else {
                $bottom = hexdec(substr($data, 8, 8));
            }
            // motorola stores them top-bottom
            if ($type == 'SRATIONAL' && $top > 2147483647) {
                $top = $top - 4294967296.0;
            }
            // this makes the number signed instead of unsigned
            if ($bottom != 0) {
                $data = $top / $bottom;
            } else {
                if ($top == 0) {
                    $data = 0;
                } else {
                    $data = $top . '/' . $bottom;
                }
            }
            if (($tag == '011a' || $tag == '011b') && $bottom == 1) {
                // XResolution YResolution
                $data = $top . ' dots per ResolutionUnit';
            } else {
                if ($tag == '829a') {
                    // Exposure Time
                    if ($bottom != 0) {
                        $data = $top / $bottom;
                    } else {
                        $data = 0;
                    }
                    $data = formatExposure($data);
                } else {
                    if ($tag == '829d') {
                        // FNumber
                        $data = 'f/' . $data;
                    } else {
                        if ($tag == '9204') {
                            // ExposureBiasValue
                            $data = round($data, 2) . ' EV';
                        } else {
                            if ($tag == '9205' || $tag == '9202') {
                                // ApertureValue and MaxApertureValue
                                // ApertureValue is given in the APEX Mode. Many thanks to Matthieu Froment for this code
                                // The formula is : Aperture = 2*log2(FNumber) <=> FNumber = e((Aperture.ln(2))/2)
                                $data = exp($data * log(2) / 2);
                                $data = round($data, 1);
                                // Focal is given with a precision of 1 digit.
                                $data = 'f/' . $data;
                            } else {
                                if ($tag == '920a') {
                                    // FocalLength
                                    $data = $data . ' mm';
                                } else {
                                    if ($tag == '9201') {
                                        // ShutterSpeedValue
                                        // The ShutterSpeedValue is given in the APEX mode. Many thanks to Matthieu Froment for this code
                                        // The formula is : Shutter = - log2(exposureTime) (Appendix C of EXIF spec.)
                                        // Where shutter is in APEX, log2(exposure) = ln(exposure)/ln(2)
                                        // So final formula is : exposure = exp(-ln(2).shutter)
                                        // The formula can be developed : exposure = 1/(exp(ln(2).shutter))
                                        $data = exp($data * log(2));
                                        if ($data != 0) {
                                            $data = 1 / $data;
                                        }
                                        $data = formatExposure($data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else {
            if ($type == 'USHORT' || $type == 'SSHORT' || $type == 'ULONG' || $type == 'SLONG' || $type == 'FLOAT' || $type == 'DOUBLE') {
                $data = bin2hex($data);
                if ($intel == 1) {
                    $data = intel2Moto($data);
                }
                if ($intel == 0 && ($type == 'USHORT' || $type == 'SSHORT')) {
                    $data = substr($data, 0, 4);
                }
                $data = hexdec($data);
                if ($type == 'SSHORT' && $data > 32767) {
                    $data = $data - 65536;
                }
                // this makes the number signed instead of unsigned
                if ($type == 'SLONG' && $data > 2147483647) {
                    $data = $data - 4294967296.0;
                }
                // this makes the number signed instead of unsigned
                if ($tag == '0112') {
                    // Orientation
                    // Example of how all of these tag formatters should be...
                    switch ($data) {
                        case 1:
                            $data = gettext('1: Normal (0 deg)');
                            break;
                        case 2:
                            $data = gettext('2: Mirrored');
                            break;
                        case 3:
                            $data = gettext('3: Upsidedown');
                            break;
                        case 4:
                            $data = gettext('4: Upsidedown Mirrored');
                            break;
                        case 5:
                            $data = gettext('5: 90 deg CW Mirrored');
                            break;
                        case 6:
                            $data = gettext('6: 90 deg CCW');
                            break;
                        case 7:
                            $data = gettext('7: 90 deg CCW Mirrored');
                            break;
                        case 8:
                            $data = gettext('8: 90 deg CW');
                            break;
                        default:
                            $data = gettext('Unknown') . ': ' . $data;
                    }
                } else {
                    if ($tag == '0128' || $tag == 'a210' || $tag == '0128') {
                        // ResolutionUnit and FocalPlaneResolutionUnit and ThumbnailResolutionUnit
                        if ($data == 1) {
                            $data = gettext('No Unit');
                        } else {
                            if ($data == 2) {
                                $data = gettext('Inch');
                            } else {
                                if ($data == 3) {
                                    $data = gettext('Centimeter');
                                }
                            }
                        }
                    } else {
                        if ($tag == '0213') {
                            // YCbCrPositioning
                            if ($data == 1) {
                                $data = gettext('Center of Pixel Array');
                            } else {
                                if ($data == 2) {
                                    $data = gettext('Datum Point');
                                }
                            }
                        } else {
                            if ($tag == '8822') {
                                // ExposureProgram
                                if ($data == 1) {
                                    $data = gettext('Manual');
                                } else {
                                    if ($data == 2) {
                                        $data = gettext('Program');
                                    } else {
                                        if ($data == 3) {
                                            $data = gettext('Aperture Priority');
                                        } else {
                                            if ($data == 4) {
                                                $data = gettext('Shutter Priority');
                                            } else {
                                                if ($data == 5) {
                                                    $data = gettext('Program Creative');
                                                } else {
                                                    if ($data == 6) {
                                                        $data = gettext('Program Action');
                                                    } else {
                                                        if ($data == 7) {
                                                            $data = gettext('Portrat');
                                                        } else {
                                                            if ($data == 8) {
                                                                $data = gettext('Landscape');
                                                            } else {
                                                                $data = gettext('Unknown') . ': ' . $data;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } else {
                                if ($tag == '9207') {
                                    // MeteringMode
                                    if ($data == 0) {
                                        $data = gettext('Unknown');
                                    } else {
                                        if ($data == 1) {
                                            $data = gettext('Average');
                                        } else {
                                            if ($data == 2) {
                                                $data = gettext('Center Weighted Average');
                                            } else {
                                                if ($data == 3) {
                                                    $data = gettext('Spot');
                                                } else {
                                                    if ($data == 4) {
                                                        $data = gettext('Multi-Spot');
                                                    } else {
                                                        if ($data == 5) {
                                                            $data = gettext('Multi-Segment');
                                                        } else {
                                                            if ($data == 6) {
                                                                $data = gettext('Partial');
                                                            } else {
                                                                if ($data == 255) {
                                                                    $data = gettext('Other');
                                                                } else {
                                                                    $data = gettext('Unknown') . ': ' . $data;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if ($tag == '9208') {
                                        // LightSource
                                        if ($data == 0) {
                                            $data = gettext('Unknown or Auto');
                                        } else {
                                            if ($data == 1) {
                                                $data = gettext('Daylight');
                                            } else {
                                                if ($data == 2) {
                                                    $data = gettext('Flourescent');
                                                } else {
                                                    if ($data == 3) {
                                                        $data = gettext('Tungsten');
                                                    } else {
                                                        if ($data == 10) {
                                                            $data = gettext('Flash');
                                                        } else {
                                                            if ($data == 17) {
                                                                $data = gettext('Standard Light A');
                                                            } else {
                                                                if ($data == 18) {
                                                                    $data = gettext('Standard Light B');
                                                                } else {
                                                                    if ($data == 19) {
                                                                        $data = gettext('Standard Light C');
                                                                    } else {
                                                                        if ($data == 20) {
                                                                            $data = gettext('D55');
                                                                        } else {
                                                                            if ($data == 21) {
                                                                                $data = gettext('D65');
                                                                            } else {
                                                                                if ($data == 22) {
                                                                                    $data = gettext('D75');
                                                                                } else {
                                                                                    if ($data == 23) {
                                                                                        $data = gettext('D50');
                                                                                    } else {
                                                                                        if ($data == 24) {
                                                                                            $data = gettext('ISO Studio Tungsten');
                                                                                        } else {
                                                                                            if ($data == 255) {
                                                                                                $data = gettext('Other');
                                                                                            } else {
                                                                                                $data = gettext('Unknown') . ': ' . $data;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if ($tag == '9209') {
                                            // Flash
                                            if ($data == 0) {
                                                $data = gettext('No Flash');
                                            } else {
                                                if ($data == 1) {
                                                    $data = gettext('Flash');
                                                } else {
                                                    if ($data == 5) {
                                                        $data = gettext('Flash, strobe return light not detected');
                                                    } else {
                                                        if ($data == 7) {
                                                            $data = gettext('Flash, strobe return light detected');
                                                        } else {
                                                            if ($data == 9) {
                                                                $data = gettext('Compulsory Flash');
                                                            } else {
                                                                if ($data == 13) {
                                                                    $data = gettext('Compulsory Flash, Return light not detected');
                                                                } else {
                                                                    if ($data == 15) {
                                                                        $data = gettext('Compulsory Flash, Return light detected');
                                                                    } else {
                                                                        if ($data == 16) {
                                                                            $data = gettext('No Flash');
                                                                        } else {
                                                                            if ($data == 24) {
                                                                                $data = gettext('No Flash');
                                                                            } else {
                                                                                if ($data == 25) {
                                                                                    $data = gettext('Flash, Auto-Mode');
                                                                                } else {
                                                                                    if ($data == 29) {
                                                                                        $data = gettext('Flash, Auto-Mode, Return light not detected');
                                                                                    } else {
                                                                                        if ($data == 31) {
                                                                                            $data = gettext('Flash, Auto-Mode, Return light detected');
                                                                                        } else {
                                                                                            if ($data == 32) {
                                                                                                $data = gettext('No Flash');
                                                                                            } else {
                                                                                                if ($data == 65) {
                                                                                                    $data = gettext('Red Eye');
                                                                                                } else {
                                                                                                    if ($data == 69) {
                                                                                                        $data = gettext('Red Eye, Return light not detected');
                                                                                                    } else {
                                                                                                        if ($data == 71) {
                                                                                                            $data = gettext('Red Eye, Return light detected');
                                                                                                        } else {
                                                                                                            if ($data == 73) {
                                                                                                                $data = gettext('Red Eye, Compulsory Flash');
                                                                                                            } else {
                                                                                                                if ($data == 77) {
                                                                                                                    $data = gettext('Red Eye, Compulsory Flash, Return light not detected');
                                                                                                                } else {
                                                                                                                    if ($data == 79) {
                                                                                                                        $data = gettext('Red Eye, Compulsory Flash, Return light detected');
                                                                                                                    } else {
                                                                                                                        if ($data == 89) {
                                                                                                                            $data = gettext('Red Eye, Auto-Mode');
                                                                                                                        } else {
                                                                                                                            if ($data == 93) {
                                                                                                                                $data = gettext('Red Eye, Auto-Mode, Return light not detected');
                                                                                                                            } else {
                                                                                                                                if ($data == 95) {
                                                                                                                                    $data = gettext('Red Eye, Auto-Mode, Return light detected');
                                                                                                                                } else {
                                                                                                                                    $data = gettext('Unknown') . ': ' . $data;
                                                                                                                                }
                                                                                                                            }
                                                                                                                        }
                                                                                                                    }
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            if ($tag == 'a001') {
                                                // ColorSpace
                                                if ($data == 1) {
                                                    $data = gettext('sRGB');
                                                } else {
                                                    $data = gettext('Uncalibrated');
                                                }
                                            } else {
                                                if ($tag == 'a002' || $tag == 'a003') {
                                                    // ExifImageWidth/Height
                                                    $data = $data . ' ' . gettext('pixels');
                                                } else {
                                                    if ($tag == '0103') {
                                                        // Compression
                                                        if ($data == 1) {
                                                            $data = gettext('No Compression');
                                                        } else {
                                                            if ($data == 6) {
                                                                $data = gettext('Jpeg Compression');
                                                            } else {
                                                                $data = gettext('Unknown') . ': ' . $data;
                                                            }
                                                        }
                                                    } else {
                                                        if ($tag == 'a217') {
                                                            // SensingMethod
                                                            if ($data == 1) {
                                                                $data = gettext('Not defined');
                                                            }
                                                            if ($data == 2) {
                                                                $data = gettext('One Chip Color Area Sensor');
                                                            }
                                                            if ($data == 3) {
                                                                $data = gettext('Two Chip Color Area Sensor');
                                                            }
                                                            if ($data == 4) {
                                                                $data = gettext('Three Chip Color Area Sensor');
                                                            }
                                                            if ($data == 5) {
                                                                $data = gettext('Color Sequential Area Sensor');
                                                            }
                                                            if ($data == 7) {
                                                                $data = gettext('Trilinear Sensor');
                                                            }
                                                            if ($data == 8) {
                                                                $data = gettext('Color Sequential Linear Sensor');
                                                            } else {
                                                                $data = gettext('Unknown') . ': ' . $data;
                                                            }
                                                        } else {
                                                            if ($tag == '0106') {
                                                                // PhotometricInterpretation
                                                                if ($data == 1) {
                                                                    $data = gettext('Monochrome');
                                                                } else {
                                                                    if ($data == 2) {
                                                                        $data = gettext('RGB');
                                                                    } else {
                                                                        if ($data == 6) {
                                                                            $data = gettext('YCbCr');
                                                                        } else {
                                                                            $data = gettext('Unknown') . ': ' . $data;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //} else if($tag=="a408" || $tag=="a40a") { // Contrast, Sharpness
                //	switch($data) {
                //		case 0: $data="Normal"; break;
                //		case 1: $data="Soft"; break;
                //		case 2: $data="Hard"; break;
                //		default: $data="Unknown"; break;
                //	}
                //} else if($tag=="a409") { // Saturation
                //	switch($data) {
                //		case 0: $data="Normal"; break;
                //		case 1: $data="Low saturation"; break;
                //		case 2: $data="High saturation"; break;
                //		default: $data="Unknown"; break;
                //	}
                //} else if($tag=="a402") { // Exposure Mode
                //	switch($data) {
                //		case 0: $data="Auto exposure"; break;
                //		case 1: $data="Manual exposure"; break;
                //		case 2: $data="Auto bracket"; break;
                //		default: $data="Unknown"; break;
                //	}
            } else {
                if ($type == 'UNDEFINED') {
                    if ($tag == '9000' || $tag == 'a000' || $tag == '0002') {
                        // ExifVersion,FlashPixVersion,InteroperabilityVersion
                        $data = gettext('version') . ' ' . $data / 100;
                    }
                    if ($tag == 'a300') {
                        // FileSource
                        $data = bin2hex($data);
                        $data = str_replace('00', '', $data);
                        $data = str_replace('03', gettext('Digital Still Camera'), $data);
                    }
                    if ($tag == 'a301') {
                        // SceneType
                        $data = bin2hex($data);
                        $data = str_replace('00', '', $data);
                        $data = str_replace('01', gettext('Directly Photographed'), $data);
                    }
                    if ($tag == '9101') {
                        // ComponentsConfiguration
                        $data = bin2hex($data);
                        $data = str_replace('01', 'Y', $data);
                        $data = str_replace('02', 'Cb', $data);
                        $data = str_replace('03', 'Cr', $data);
                        $data = str_replace('04', 'R', $data);
                        $data = str_replace('05', 'G', $data);
                        $data = str_replace('06', 'B', $data);
                        $data = str_replace('00', '', $data);
                    }
                    //if($tag=="9286") { //UserComment
                    //	$encoding	= rtrim(substr($data, 0, 8));
                    //	$data		= rtrim(substr($data, 8));
                    //}
                } else {
                    $data = bin2hex($data);
                    if ($intel == 1) {
                        $data = intel2Moto($data);
                    }
                }
            }
        }
    }
    return $data;
}
Exemplo n.º 3
0
function formatData($type, $tag, $intel, $data)
{
    global $LANG_MG04;
    if ($type == 'ASCII') {
        // Search for a null byte and stop there.
        if (($pos = strpos($data, chr(0))) !== false) {
            $data = substr($data, 0, $pos);
        }
        // Format certain kinds of strings nicely (Camera make etc.)
        if ($tag == '010f') {
            $data = ucwords(strtolower(trim($data)));
        }
    } else {
        if ($type == 'URATIONAL' || $type == 'SRATIONAL') {
            $data = bin2hex($data);
            if ($intel == 1) {
                $data = intel2Moto($data);
            }
            if ($intel == 1) {
                $top = hexdec(substr($data, 8, 8));
            } else {
                $top = hexdec(substr($data, 0, 8));
            }
            // motorola stores them top-bottom
            if ($intel == 1) {
                $bottom = hexdec(substr($data, 0, 8));
            } else {
                $bottom = hexdec(substr($data, 8, 8));
            }
            // motorola stores them top-bottom
            if ($type == 'SRATIONAL' && $top > 2147483647) {
                $top = $top - 4294967296;
            }
            // this makes the number signed instead of unsigned
            if ($bottom != 0) {
                $data = $top / $bottom;
            } else {
                if ($top == 0) {
                    $data = 0;
                } else {
                    $data = $top . '/' . $bottom;
                }
            }
            if (($tag == '011a' || $tag == '011b') && $bottom == 1) {
                // XResolution YResolution
                $data = $top . ' dots per ResolutionUnit';
            } else {
                if ($tag == '829a') {
                    // Exposure Time
                    if ($bottom != 0) {
                        $data = $top / $bottom;
                    } else {
                        $data = 0;
                    }
                    $data = formatExposure($data);
                } else {
                    if ($tag == '829d') {
                        // FNumber
                        $data = 'f/' . $data;
                    } else {
                        if ($tag == '9204') {
                            // ExposureBiasValue
                            $data = round($data, 2) . ' EV';
                        } else {
                            if ($tag == '9205' || $tag == '9202') {
                                // ApertureValue and MaxApertureValue
                                // ApertureValue is given in the APEX Mode. Many thanks to Matthieu Froment for this code
                                // The formula is : Aperture = 2*log2(FNumber) <=> FNumber = e((Aperture.ln(2))/2)
                                $data = exp($data * log(2) / 2);
                                $data = round($data, 1);
                                // Focal is given with a precision of 1 digit.
                                $data = 'f/' . $data;
                            } else {
                                if ($tag == '920a') {
                                    // FocalLength
                                    $data = $data . ' mm';
                                } else {
                                    if ($tag == '9201') {
                                        // ShutterSpeedValue
                                        // The ShutterSpeedValue is given in the APEX mode. Many thanks to Matthieu Froment for this code
                                        // The formula is : Shutter = - log2(exposureTime) (Appendix C of EXIF spec.)
                                        // Where shutter is in APEX, log2(exposure) = ln(exposure)/ln(2)
                                        // So final formula is : exposure = exp(-ln(2).shutter)
                                        // The formula can be developed : exposure = 1/(exp(ln(2).shutter))
                                        $data = exp($data * log(2));
                                        if ($data != 0) {
                                            $data = 1 / $data;
                                        }
                                        $data = formatExposure($data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else {
            if ($type == 'USHORT' || $type == 'SSHORT' || $type == 'ULONG' || $type == 'SLONG' || $type == 'FLOAT' || $type == 'DOUBLE') {
                $data = bin2hex($data);
                if ($intel == 1) {
                    $data = intel2Moto($data);
                }
                if ($intel == 0 && ($type == 'USHORT' || $type == 'SSHORT')) {
                    $data = substr($data, 0, 4);
                }
                $data = hexdec($data);
                if ($type == 'SSHORT' && $data > 32767) {
                    $data = $data - 65536;
                }
                // this makes the number signed instead of unsigned
                if ($type == 'SLONG' && $data > 2147483647) {
                    $data = $data - 4294967296;
                }
                // this makes the number signed instead of unsigned
                if ($tag == '0112') {
                    // Orientation
                    // Example of how all of these tag formatters should be...
                    switch ($data) {
                        case 1:
                            $data = $LANG_MG04['normal'];
                            break;
                        case 2:
                            $data = $LANG_MG04['mirrored'];
                            break;
                        case 3:
                            $data = $LANG_MG04['upsidedown'];
                            break;
                        case 4:
                            $data = $LANG_MG04['upsidedown_mirrored'];
                            break;
                        case 5:
                            $data = $LANG_MG04['cw_mirrored'];
                            break;
                        case 6:
                            $data = $LANG_MG04['ccw'];
                            break;
                        case 7:
                            $data = $LANG_MG04['ccw_mirrored'];
                            break;
                        case 8:
                            $data = $LANG_MG04['cw'];
                            break;
                        default:
                            $data = $LANG_MG04['unknown'] . ': ' . $data;
                    }
                } else {
                    if ($tag == '0128' || $tag == 'a210' || $tag == '0128') {
                        // ResolutionUnit and FocalPlaneResolutionUnit and ThumbnailResolutionUnit
                        if ($data == 1) {
                            $data = $LANG_MG04['no_unit'];
                        } else {
                            if ($data == 2) {
                                $data = $LANG_MG04['inch'];
                            } else {
                                if ($data == 3) {
                                    $data = $LANG_MG04['centimeter'];
                                }
                            }
                        }
                    } else {
                        if ($tag == '0213') {
                            // YCbCrPositioning
                            if ($data == 1) {
                                $data = $LANG_MG04['center_of_pixel_array'];
                            }
                            if ($data == 2) {
                                $data = $LANG_MG04['datum_point'];
                            }
                        } else {
                            if ($tag == '8822') {
                                // ExposureProgram
                                if ($data == 1) {
                                    $data = $LANG_MG04['manual'];
                                } else {
                                    if ($data == 2) {
                                        $data = $LANG_MG04['program'];
                                    } else {
                                        if ($data == 3) {
                                            $data = $LANG_MG04['aperature_priority'];
                                        } else {
                                            if ($data == 4) {
                                                $data = $LANG_MG04['shutter_priority'];
                                            } else {
                                                if ($data == 5) {
                                                    $data = $LANG_MG04['program_creative'];
                                                } else {
                                                    if ($data == 6) {
                                                        $data = $LANG_MG04['program_action'];
                                                    } else {
                                                        if ($data == 7) {
                                                            $data = $LANG_MG04['portrait'];
                                                        } else {
                                                            if ($data == 8) {
                                                                $data = $LANG_MG04['landscape'];
                                                            } else {
                                                                $data = "Unknown: " . $data;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } else {
                                if ($tag == '9207') {
                                    // MeteringMode
                                    if ($data == 0) {
                                        $data = $LANG_MG04['unknown'];
                                    } else {
                                        if ($data == 1) {
                                            $data = $LANG_MG04['average'];
                                        } else {
                                            if ($data == 2) {
                                                $data = $LANG_MG04['center_weighted_average'];
                                            } else {
                                                if ($data == 3) {
                                                    $data = $LANG_MG04['spot'];
                                                } else {
                                                    if ($data == 4) {
                                                        $data = $LANG_MG04['multi_spot'];
                                                    } else {
                                                        if ($data == 5) {
                                                            $data = $LANG_MG04['multi_segment'];
                                                        } else {
                                                            if ($data == 6) {
                                                                $data = $LANG_MG04['partial'];
                                                            } else {
                                                                if ($data == 255) {
                                                                    $data = $LANG_MG04['other'];
                                                                } else {
                                                                    $data = "Unknown: " . $data;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    if ($tag == '9208') {
                                        // LightSource
                                        if ($data == 0) {
                                            $data = $LANG_MG04['unknown_or_auto'];
                                        } else {
                                            if ($data == 1) {
                                                $data = $LANG_MG04['daylight'];
                                            } else {
                                                if ($data == 2) {
                                                    $data = $LANG_MG04['flourescent'];
                                                } else {
                                                    if ($data == 3) {
                                                        $data = $LANG_MG04['tungsten'];
                                                    } else {
                                                        if ($data == 10) {
                                                            $data = $LANG_MG04['flash'];
                                                        } else {
                                                            if ($data == 17) {
                                                                $data = $LANG_MG04['standard_a'];
                                                            } else {
                                                                if ($data == 18) {
                                                                    $data = $LANG_MG04['standard_b'];
                                                                } else {
                                                                    if ($data == 19) {
                                                                        $data = $LANG_MG04['standard_c'];
                                                                    } else {
                                                                        if ($data == 20) {
                                                                            $data = $LANG_MG04['d55'];
                                                                        } else {
                                                                            if ($data == 21) {
                                                                                $data = $LANG_MG04['d65'];
                                                                            } else {
                                                                                if ($data == 22) {
                                                                                    $data = $LANG_MG04['d75'];
                                                                                } else {
                                                                                    if ($data == 23) {
                                                                                        $data = 'D50';
                                                                                    } else {
                                                                                        if ($data == 24) {
                                                                                            $data = 'ISO Studio Tungsten';
                                                                                        } else {
                                                                                            if ($data == 255) {
                                                                                                $data = $LANG_MG04['other'];
                                                                                            } else {
                                                                                                $data = 'Unknown' . ': ' . $data;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        if ($tag == '9209') {
                                            // Flash
                                            if ($data == 0) {
                                                $data = $LANG_MG04['flash_00'];
                                            } else {
                                                if ($data == 1) {
                                                    $data = $LANG_MG04['flash_01'];
                                                } else {
                                                    if ($data == 5) {
                                                        $data = $LANG_MG04['flash_05'];
                                                    } else {
                                                        if ($data == 7) {
                                                            $data = $LANG_MG04['flash_07'];
                                                        } else {
                                                            if ($data == 9) {
                                                                $data = $LANG_MG04['flash_09'];
                                                            } else {
                                                                if ($data == 13) {
                                                                    $data = $LANG_MG04['flash_13'];
                                                                } else {
                                                                    if ($data == 15) {
                                                                        $data = $LANG_MG04['flash_15'];
                                                                    } else {
                                                                        if ($data == 16) {
                                                                            $data = $LANG_MG04['flash_16'];
                                                                        } else {
                                                                            if ($data == 24) {
                                                                                $data = $LANG_MG04['flash_24'];
                                                                            } else {
                                                                                if ($data == 25) {
                                                                                    $data = $LANG_MG04['flash_25'];
                                                                                } else {
                                                                                    if ($data == 29) {
                                                                                        $data = $LANG_MG04['flash_29'];
                                                                                    } else {
                                                                                        if ($data == 31) {
                                                                                            $data = $LANG_MG04['flash_31'];
                                                                                        } else {
                                                                                            if ($data == 32) {
                                                                                                $data = $LANG_MG04['flash_32'];
                                                                                            } else {
                                                                                                if ($data == 65) {
                                                                                                    $data = $LANG_MG04['flash_65'];
                                                                                                } else {
                                                                                                    if ($data == 69) {
                                                                                                        $data = $LANG_MG04['flash_69'];
                                                                                                    } else {
                                                                                                        if ($data == 71) {
                                                                                                            $data = $LANG_MG04['flash_71'];
                                                                                                        } else {
                                                                                                            if ($data == 73) {
                                                                                                                $data = $LANG_MG04['flash_73'];
                                                                                                            } else {
                                                                                                                if ($data == 77) {
                                                                                                                    $data = $LANG_MG04['flash_77'];
                                                                                                                } else {
                                                                                                                    if ($data == 79) {
                                                                                                                        $data = $LANG_MG04['flash_79'];
                                                                                                                    } else {
                                                                                                                        if ($data == 89) {
                                                                                                                            $data = $LANG_MG04['flash_89'];
                                                                                                                        } else {
                                                                                                                            if ($data == 93) {
                                                                                                                                $data = $LANG_MG04['flash_93'];
                                                                                                                            } else {
                                                                                                                                if ($data == 95) {
                                                                                                                                    $data = $LANG_MG04['flash_95'];
                                                                                                                                } else {
                                                                                                                                    $data = $LANG_MG04['unknown'] . ": " . $data;
                                                                                                                                }
                                                                                                                            }
                                                                                                                        }
                                                                                                                    }
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            if ($tag == 'a001') {
                                                // ColorSpace
                                                if ($data == 1) {
                                                    $data = $LANG_MG04['srgb'];
                                                } else {
                                                    $data = $LANG_MG04['uncalibrated'];
                                                }
                                            } else {
                                                if ($tag == 'a002' || $tag == 'a003') {
                                                    // ExifImageWidth/Height
                                                    $data = $data . $LANG_MG04['pixels'];
                                                } else {
                                                    if ($tag == '0103') {
                                                        // Compression
                                                        if ($data == 1) {
                                                            $data = $LANG_MG04['no_compression'];
                                                        } else {
                                                            if ($data == 6) {
                                                                $data = $LANG_MG04['jpeg_compression'];
                                                            } else {
                                                                $data = $LANG_MG04['unknown'] . ": " . $data;
                                                            }
                                                        }
                                                    } else {
                                                        if ($tag == 'a217') {
                                                            // SensingMethod
                                                            if ($data == 1) {
                                                                $data = $LANG_MG04['not_defined'];
                                                            }
                                                            if ($data == 2) {
                                                                $data = $LANG_MG04['one_chip_color_area_sensor'];
                                                            }
                                                            if ($data == 3) {
                                                                $data = $LANG_MG04['two_chip_color_area_sensor'];
                                                            }
                                                            if ($data == 4) {
                                                                $data = $LANG_MG04['three_chip_color_area_sensor'];
                                                            }
                                                            if ($data == 5) {
                                                                $data = $LANG_MG04['color_sequential_area_sensor'];
                                                            }
                                                            if ($data == 7) {
                                                                $data = $LANG_MG04['trilinear_sensor'];
                                                            }
                                                            if ($data == 8) {
                                                                $data = $LANG_MG04['color_sequential_linear_sensor'];
                                                            } else {
                                                                $data = $LANG_MG04['unknown'] . ": " . $data;
                                                            }
                                                        } else {
                                                            if ($tag == '0106') {
                                                                // PhotometricInterpretation
                                                                if ($data == 1) {
                                                                    $data = $LANG_MG04['monochrome'];
                                                                } else {
                                                                    if ($data == 2) {
                                                                        $data = $LANG_MG04['rgb'];
                                                                    } else {
                                                                        if ($data == 6) {
                                                                            $data = $LANG_MG04['ycbcr'];
                                                                        } else {
                                                                            $data = $LANG_MG04['unknown'] . ": " . $data;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                //} else if($tag=="a408" || $tag=="a40a") { // Contrast, Sharpness
                //	switch($data) {
                //		case 0: $data="Normal"; break;
                //		case 1: $data="Soft"; break;
                //		case 2: $data="Hard"; break;
                //		default: $data="Unknown"; break;
                //	}
                //} else if($tag=="a409") { // Saturation
                //	switch($data) {
                //		case 0: $data="Normal"; break;
                //		case 1: $data="Low saturation"; break;
                //		case 2: $data="High saturation"; break;
                //		default: $data="Unknown"; break;
                //	}
                //} else if($tag=="a402") { // Exposure Mode
                //	switch($data) {
                //		case 0: $data="Auto exposure"; break;
                //		case 1: $data="Manual exposure"; break;
                //		case 2: $data="Auto bracket"; break;
                //		default: $data="Unknown"; break;
                //	}
            } else {
                if ($type == 'UNDEFINED') {
                    if ($tag == '9000' || $tag == 'a000' || $tag == '0002') {
                        // ExifVersion,FlashPixVersion,InteroperabilityVersion
                        $data = 'version' . ' ' . $data / 100;
                    }
                    if ($tag == 'a300') {
                        // FileSource
                        $data = bin2hex($data);
                        $data = str_replace('00', '', $data);
                        $data = str_replace("03", $LANG_MG04['digital_still_camera'], $data);
                    }
                    if ($tag == 'a301') {
                        // SceneType
                        $data = bin2hex($data);
                        $data = str_replace('00', '', $data);
                        $data = str_replace("01", $LANG_MG04['directly_photographed'], $data);
                    }
                    if ($tag == '9101') {
                        // ComponentsConfiguration
                        $data = bin2hex($data);
                        $data = str_replace('01', 'Y', $data);
                        $data = str_replace('02', 'Cb', $data);
                        $data = str_replace('03', 'Cr', $data);
                        $data = str_replace('04', 'R', $data);
                        $data = str_replace('05', 'G', $data);
                        $data = str_replace('06', 'B', $data);
                        $data = str_replace('00', '', $data);
                    }
                    //if($tag=="9286") { //UserComment
                    //	$encoding	= rtrim(substr($data, 0, 8));
                    //	$data		= rtrim(substr($data, 8));
                    //}
                } else {
                    $data = bin2hex($data);
                    if ($intel == 1) {
                        $data = intel2Moto($data);
                    }
                }
            }
        }
    }
    return $data;
}
Exemplo n.º 4
0
 /**
  * Filter for handling image objects
  *
  * @param object $image
  * @return object
  */
 static function new_image($image)
 {
     global $_zp_exifvars;
     $source = '';
     $metadata_path = '';
     $files = safe_glob(substr($image->localpath, 0, strrpos($image->localpath, '.')) . '.*');
     if (count($files) > 0) {
         foreach ($files as $file) {
             if (strtolower(getSuffix($file)) == XMP_EXTENSION) {
                 $metadata_path = $file;
                 break;
             }
         }
     }
     if (!empty($metadata_path)) {
         $source = self::extractXMP(file_get_contents($metadata_path));
     } else {
         if (getOption('xmpMetadata_examine_images_' . strtolower(substr(strrchr($image->localpath, "."), 1)))) {
             $f = file_get_contents($image->localpath);
             $l = filesize($image->localpath);
             $abort = 0;
             $i = 0;
             while ($i < $l && $abort < 200 && !$source) {
                 $tag = bin2hex(substr($f, $i, 2));
                 $size = hexdec(bin2hex(substr($f, $i + 2, 2)));
                 switch ($tag) {
                     case 'ffe1':
                         // EXIF
                     // EXIF
                     case 'ffe2':
                         // EXIF extension
                     // EXIF extension
                     case 'fffe':
                         // COM
                     // COM
                     case 'ffe0':
                         // IPTC marker
                         $source = self::extractXMP($f);
                         $i = $i + $size + 2;
                         $abort = 0;
                         break;
                     default:
                         if ($f[$i] == '<') {
                             $source = self::extractXMP($f);
                         }
                         $i = $i + 1;
                         $abort++;
                         break;
                 }
             }
         }
     }
     if (!empty($source)) {
         $metadata = self::extract($source);
         $image->set('hasMetadata', count($metadata > 0));
         foreach ($metadata as $field => $element) {
             if (array_key_exists($field, $_zp_exifvars)) {
                 if (!$_zp_exifvars[$field][5]) {
                     continue;
                     //	the field has been disabled
                 }
             }
             $v = self::to_string($element);
             switch ($field) {
                 case 'EXIFDateTimeOriginal':
                     $image->setDateTime($element);
                     break;
                 case 'IPTCImageCaption':
                     $image->setDesc($v);
                     break;
                 case 'IPTCCity':
                     $image->setCity($v);
                     break;
                 case 'IPTCState':
                     $image->setState($v);
                     break;
                 case 'IPTCLocationName':
                     $image->setCountry($v);
                     break;
                 case 'IPTCSubLocation':
                     $image->setLocation($v);
                     break;
                 case 'EXIFExposureTime':
                     $v = formatExposure(self::rationalNum($element));
                     break;
                 case 'EXIFFocalLength':
                     $v = self::rationalNum($element) . ' mm';
                     break;
                 case 'EXIFAperatureValue':
                 case 'EXIFFNumber':
                     $v = 'f/' . self::rationalNum($element);
                     break;
                 case 'EXIFExposureBiasValue':
                 case 'EXIFGPSAltitude':
                     $v = self::rationalNum($element);
                     break;
                 case 'EXIFGPSLatitude':
                 case 'EXIFGPSLongitude':
                     $ref = substr($element, -1, 1);
                     $image->set($field . 'Ref', $ref);
                     $element = substr($element, 0, -1);
                     $n = explode(',', $element);
                     if (count($n) == 3) {
                         $v = $n[0] + ($n[1] + $n[2] / 60 / 60);
                     } else {
                         $v = $n[0] + $n[1] / 60;
                     }
                     break;
                 case 'rating':
                     $v = min(getoption('rating_stars_count'), $v) * min(1, getOption('rating_split_stars'));
                     $image->set('total_value', $v);
                     $image->set('total_votes', 1);
                     break;
                 case 'watermark':
                 case 'watermark_use':
                 case 'custom_data':
                 case 'codeblock':
                 case 'owner':
                     $image->set($field, $v);
                     break;
                 case 'IPTCKeywords':
                     if (!is_array($element)) {
                         $element = explode(',', $element);
                     }
                     $image->setTags($element);
                     break;
             }
             if (array_key_exists($field, $_zp_exifvars)) {
                 $image->set($field, $v);
             }
         }
         $image->save();
     }
     return $image;
 }
Exemplo n.º 5
0
function formatData($type, $tag, $intel, $data)
{
    switch ($type) {
        case 'ASCII':
            if (($pos = strpos($data, chr(0))) !== false) {
                // Search for a null byte and stop there.
                $data = substr($data, 0, $pos);
            }
            if ($tag == '010f') {
                $data = ucwords(strtolower(trim($data)));
            }
            // Format certain kinds of strings nicely (Camera make etc.)
            break;
        case 'URATIONAL':
        case 'SRATIONAL':
            switch ($tag) {
                case '011a':
                    // XResolution
                // XResolution
                case '011b':
                    // YResolution
                    $data = round(unRational($data, $type, $intel)) . ' dots per ResolutionUnit';
                    break;
                case '829a':
                    // Exposure Time
                    $data = formatExposure(unRational($data, $type, $intel));
                    break;
                case '829d':
                    // FNumber
                    $data = 'f/' . round(unRational($data, $type, $intel), 2);
                    break;
                case '9204':
                    // ExposureBiasValue (assume signed!)
                    $data = round(unRational($data, 'SRATIONAL', $intel), 2) . ' EV';
                    break;
                case '9205':
                    // ApertureValue
                // ApertureValue
                case '9202':
                    // MaxApertureValue
                    // ApertureValue is given in the APEX Mode. Many thanks to Matthieu Froment for this code
                    // The formula is : Aperture = 2*log2(FNumber) <=> FNumber = e((Aperture.ln(2))/2)
                    $datum = exp(unRational($data, $type, $intel) * log(2) / 2);
                    $data = 'f/' . round($datum, 1);
                    // Focal is given with a precision of 1 digit.
                    break;
                case '920a':
                    // FocalLength
                    $data = unRational($data, $type, $intel) . ' mm';
                    break;
                case '9201':
                    // ShutterSpeedValue
                    // The ShutterSpeedValue is given in the APEX mode. Many thanks to Matthieu Froment for this code
                    // The formula is : Shutter = - log2(exposureTime) (Appendix C of EXIF spec.)
                    // Where shutter is in APEX, log2(exposure) = ln(exposure)/ln(2)
                    // So final formula is : exposure = exp(-ln(2).shutter)
                    // The formula can be developed : exposure = 1/(exp(ln(2).shutter))
                    $datum = exp(unRational($data, $type, $intel) * log(2));
                    if ($datum != 0) {
                        $datum = 1 / $datum;
                    }
                    $data = formatExposure($datum);
                    break;
                default:
                    $data = unRational($data, $type, $intel);
                    break;
            }
            break;
        case 'USHORT':
        case 'SSHORT':
        case 'ULONG':
        case 'SLONG':
        case 'FLOAT':
        case 'DOUBLE':
            $data = rational($data, $type, $intel);
            switch ($tag) {
                case '0112':
                    // Orientation
                    // Example of how all of these tag formatters should be...
                    switch ($data) {
                        case 0:
                            // not set, presume normal
                        // not set, presume normal
                        case 1:
                            $data = '!1: normal (0 deg)!';
                            break;
                        case 2:
                            $data = '!2: mirrored!';
                            break;
                        case 3:
                            $data = '!3: upside-down!';
                            break;
                        case 4:
                            $data = '!4: upside-down mirrored!';
                            break;
                        case 5:
                            $data = '!5: 90 deg ccw mirrored!';
                            break;
                        case 6:
                            $data = '!6: 90 deg cw!';
                            break;
                        case 7:
                            $data = '!7: 90 deg cw mirrored!';
                            break;
                        case 8:
                            $data = '!8: 90 deg ccw!';
                            break;
                        default:
                            $data = sprintf('%d: ' . '!unknown!', $data);
                            break;
                    }
                    break;
                case '0128':
                    // ResolutionUnit
                // ResolutionUnit
                case 'a210':
                    // FocalPlaneResolutionUnit
                // FocalPlaneResolutionUnit
                case '0128':
                    // ThumbnailResolutionUnit
                    switch ($data) {
                        case 1:
                            $data = '!no unit!';
                            break;
                        case 2:
                            $data = '!inch!';
                            break;
                        case 3:
                            $data = '!centimeter!';
                            break;
                    }
                    break;
                case '0213':
                    // YCbCrPositioning
                    switch ($data) {
                        case 1:
                            $data = '!center of pixel array!';
                            break;
                        case 2:
                            $data = '!datum point!';
                            break;
                    }
                    break;
                case '8822':
                    // ExposureProgram
                    switch ($data) {
                        case 1:
                            $data = '!manual!';
                            break;
                        case 2:
                            $data = '!program!';
                            break;
                        case 3:
                            $data = '!aperture priority!';
                            break;
                        case 4:
                            $data = '!shutter priority!';
                            break;
                        case 5:
                            $data = '!program creative!';
                            break;
                        case 6:
                            $data = '!program action!';
                            break;
                        case 7:
                            $data = '!portrait!';
                            break;
                        case 8:
                            $data = '!landscape!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                case '8830':
                    // SensitivityType
                    switch ($data) {
                        case 1:
                            $data = '!standard output sensitivity!';
                            break;
                        case 2:
                            $data = '!recommended exposure index!';
                            break;
                        case 3:
                            $data = '!iso speed!';
                            break;
                        case 4:
                            $data = '!standard output sensitivity and recommended exposure index!';
                            break;
                        case 5:
                            $data = '!standard output sensitivity and iso speed!';
                            break;
                        case 6:
                            $data = '!recommended exposure index and iso speed!';
                            break;
                        case 7:
                            $data = '!standard output sensitivity, recommended exposure index and iso speed!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                case '9207':
                    // MeteringMode
                    switch ($data) {
                        case 1:
                            $data = '!average!';
                            break;
                        case 2:
                            $data = '!center weighted average!';
                            break;
                        case 3:
                            $data = '!spot!';
                            break;
                        case 4:
                            $data = '!multi-spot!';
                            break;
                        case 5:
                            $data = '!pattern!';
                            break;
                        case 6:
                            $data = '!partial!';
                            break;
                        case 255:
                            $data = '!other!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                case '9208':
                    // LightSource
                    switch ($data) {
                        case 1:
                            $data = '!daylight!';
                            break;
                        case 2:
                            $data = '!fluorescent!';
                            break;
                        case 3:
                            $data = '!tungsten!';
                            break;
                            // 3 Tungsten (Incandescent light)
                            // 4 Flash
                            // 9 Fine Weather
                        // 3 Tungsten (Incandescent light)
                        // 4 Flash
                        // 9 Fine Weather
                        case 10:
                            $data = '!flash!';
                            break;
                            // 10 Cloudy Weather
                            // 11 Shade
                            // 12 Daylight Fluorescent (D 5700 - 7100K)
                            // 13 Day White Fluorescent (N 4600 - 5400K)
                            // 14 Cool White Fluorescent (W 3900 -4500K)
                            // 15 White Fluorescent (WW 3200 - 3700K)
                            // 10 Flash
                        // 10 Cloudy Weather
                        // 11 Shade
                        // 12 Daylight Fluorescent (D 5700 - 7100K)
                        // 13 Day White Fluorescent (N 4600 - 5400K)
                        // 14 Cool White Fluorescent (W 3900 -4500K)
                        // 15 White Fluorescent (WW 3200 - 3700K)
                        // 10 Flash
                        case 17:
                            $data = '!standard light a!';
                            break;
                        case 18:
                            $data = '!standard light b!';
                            break;
                        case 19:
                            $data = '!standard light c!';
                            break;
                        case 20:
                            $data = 'D55';
                            break;
                        case 21:
                            $data = 'D65';
                            break;
                        case 22:
                            $data = 'D75';
                            break;
                        case 23:
                            $data = 'D50';
                            break;
                        case 24:
                            $data = '!iso studio tungsten!';
                            break;
                        case 255:
                            $data = '!other!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                case '9209':
                    // Flash
                    switch ($data) {
                        case 0:
                        case 16:
                        case 24:
                        case 32:
                        case 64:
                        case 80:
                            $data = '!no flash!';
                            break;
                        case 1:
                            $data = '!flash!';
                            break;
                        case 5:
                            $data = '!flash, strobe return light not detected!';
                            break;
                        case 7:
                            $data = '!flash, strobe return light detected!';
                            break;
                        case 9:
                            $data = '!compulsory flash!';
                            break;
                        case 13:
                            $data = '!compulsory flash, return light not detected!';
                            break;
                        case 15:
                            $data = '!compulsory flash, return light detected!';
                            break;
                        case 25:
                            $data = '!flash, auto-mode!';
                            break;
                        case 29:
                            $data = '!flash, auto-mode, return light not detected!';
                            break;
                        case 31:
                            $data = '!flash, auto-mode, return light detected!';
                            break;
                        case 65:
                            $data = '!red eye!';
                            break;
                        case 69:
                            $data = '!red eye, return light not detected!';
                            break;
                        case 71:
                            $data = '!red eye, return light detected!';
                            break;
                        case 73:
                            $data = '!red eye, compulsory flash!';
                            break;
                        case 77:
                            $data = '!red eye, compulsory flash, return light not detected!';
                            break;
                        case 79:
                            $data = '!red eye, compulsory flash, return light detected!';
                            break;
                        case 89:
                            $data = '!red eye, auto-mode!';
                            break;
                        case 93:
                            $data = '!red eye, auto-mode, return light not detected!';
                            break;
                        case 95:
                            $data = '!red eye, auto-mode, return light detected!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                case 'a001':
                    // ColorSpace
                    if ($data == 1) {
                        $data = '!srgb!';
                    } else {
                        $data = '!uncalibrated!';
                    }
                    break;
                case 'a002':
                    // ExifImageWidth
                // ExifImageWidth
                case 'a003':
                    // ExifImageHeight
                    $data = $data . ' ' . '!pixels!';
                    break;
                case '0103':
                    // Compression
                    switch ($data) {
                        case 1:
                            $data = '!no compression!';
                            break;
                        case 6:
                            $data = '!jpeg compression!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                case 'a217':
                    // SensingMethod
                    switch ($data) {
                        case 1:
                            $data = '!not defined!';
                            break;
                        case 2:
                            $data = '!one chip color area sensor!';
                            break;
                        case 3:
                            $data = '!two chip color area sensor!';
                            break;
                        case 4:
                            $data = '!three chip color area sensor!';
                            break;
                        case 5:
                            $data = '!color sequential area sensor!';
                            break;
                        case 7:
                            $data = '!trilinear sensor!';
                            break;
                        case 8:
                            $data = '!color sequential linear sensor!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                case '0106':
                    // PhotometricInterpretation
                    switch ($data) {
                        case 1:
                            $data = '!monochrome!';
                            break;
                        case 2:
                            $data = '!rgb!';
                            break;
                        case 6:
                            $data = '!ycbcr!';
                            break;
                        default:
                            $data = '!unknown!' . ': ' . $data;
                            break;
                    }
                    break;
                    //case "a408":	// Contrast
                    //case "a40a":	//Sharpness
                    //	switch($data) {
                    //		case 0: $data="Normal"; break;
                    //		case 1: $data="Soft"; break;
                    //		case 2: $data="Hard"; break;
                    //		default: $data="Unknown"; break;
                    //	}
                    //	break;
                    //case "a409":	// Saturation
                    //	switch($data) {
                    //		case 0: $data="Normal"; break;
                    //		case 1: $data="Low saturation"; break;
                    //		case 2: $data="High saturation"; break;
                    //		default: $data="Unknown"; break;
                    //	}
                    //	break;
                    //case "a402":	// Exposure Mode
                    //	switch($data) {
                    //		case 0: $data="Auto exposure"; break;
                    //		case 1: $data="Manual exposure"; break;
                    //		case 2: $data="Auto bracket"; break;
                    //		default: $data="Unknown"; break;
                    //	}
                    //	break;
            }
            break;
        case 'UNDEFINED':
            switch ($tag) {
                case '9000':
                    // ExifVersion
                // ExifVersion
                case 'a000':
                    // FlashPixVersion
                // FlashPixVersion
                case '0002':
                    // InteroperabilityVersion
                    $data = '!version!' . ' ' . $data / 100;
                    break;
                case 'a300':
                    // FileSource
                    $data = bin2hex($data);
                    $data = str_replace('00', '', $data);
                    $data = str_replace('03', '!digital still camera!', $data);
                    break;
                case 'a301':
                    // SceneType
                    $data = bin2hex($data);
                    $data = str_replace('00', '', $data);
                    $data = str_replace('01', '!directly photographed!', $data);
                    break;
                case '9101':
                    // ComponentsConfiguration
                    $data = bin2hex($data);
                    $data = str_replace('01', 'Y', $data);
                    $data = str_replace('02', 'Cb', $data);
                    $data = str_replace('03', 'Cr', $data);
                    $data = str_replace('04', 'R', $data);
                    $data = str_replace('05', 'G', $data);
                    $data = str_replace('06', 'B', $data);
                    $data = str_replace('00', '', $data);
                    break;
                    //case "9286":	//UserComment
                    //	$encoding	= rtrim(substr($data, 0, 8));
                    //	$data		= rtrim(substr($data, 8));
                    //	break;
            }
            break;
        default:
            $data = bin2hex($data);
            if ($intel == 1) {
                $data = intel2Moto($data);
            }
            break;
    }
    return $data;
}
Exemplo n.º 6
0
 /**
  * Filter for handling image objects
  *
  * @param object $image
  * @return object
  */
 static function new_image($image)
 {
     $source = '';
     $metadata_path = '';
     $files = safe_glob(substr($image->localpath, 0, strrpos($image->localpath, '.')) . '.*');
     if (count($files) > 0) {
         foreach ($files as $file) {
             if (strtolower(getSuffix($file)) == XMP_EXTENSION) {
                 $metadata_path = $file;
                 break;
             }
         }
     }
     if (!empty($metadata_path)) {
         $source = self::extractXMP(file_get_contents($metadata_path));
     } else {
         if (getOption('xmpMetadata_examine_images_' . strtolower(substr(strrchr($image->localpath, "."), 1)))) {
             $f = file_get_contents($image->localpath);
             $l = filesize($image->localpath);
             $abort = 0;
             $i = 0;
             while ($i < $l && $abort < 200 && !$source) {
                 $tag = bin2hex(substr($f, $i, 2));
                 $size = hexdec(bin2hex(substr($f, $i + 2, 2)));
                 switch ($tag) {
                     case 'ffe1':
                         // EXIF
                     // EXIF
                     case 'ffe2':
                         // EXIF extension
                     // EXIF extension
                     case 'fffe':
                         // COM
                     // COM
                     case 'ffe0':
                         // IPTC marker
                         $source = self::extractXMP($f);
                         $i = $i + $size + 2;
                         $abort = 0;
                         break;
                     default:
                         if ($f[$i] == '<') {
                             $source = self::extractXMP($f);
                         }
                         $i = $i + 1;
                         $abort++;
                         break;
                 }
             }
         }
     }
     // direct import to ZenPhoto20 fields with no processing required
     $import = array('location' => 'XMPSubLocation', 'city' => 'XMPCity', 'city' => 'XMPCity', 'state' => 'XMPState', 'country' => 'XMPLocationName', 'copyright' => 'XMPCopyright', 'rotation' => 'XMPOrientation');
     if (!empty($source)) {
         $metadata = self::extract($source);
         if (count($metadata > 0)) {
             $exifVars = self::getMetadataFields();
             foreach ($metadata as $field => $element) {
                 if (!array_key_exists($field, $exifVars) || $exifVars[$field][5]) {
                     $image->set('hasMetadata', 1);
                     $v = self::to_string($element);
                     if (($key = array_search($field, $import)) !== false) {
                         $image->set($key, $v);
                     } else {
                         switch ($field) {
                             case 'XMPSource':
                                 if (!isset($metadata['XMPImageCredit'])) {
                                     $this->set('credit', $v);
                                 }
                                 break;
                             case 'XMPImageCredit':
                                 $this->set('credit', $v);
                                 break;
                             case 'XMPImageHeadline':
                                 if (getoption('transform_newlines')) {
                                     $v = nl2br($v);
                                 }
                                 $image->setTitle($v);
                                 break;
                             case 'XMPImageCaption':
                                 if (getoption('transform_newlines')) {
                                     $v = nl2br(v);
                                 }
                                 $image->setDesc($v);
                                 break;
                             case 'XMPDateTimeOriginal':
                                 $image->setDateTime($element);
                                 break;
                             case 'XMPExposureTime':
                                 $v = formatExposure(self::rationalNum($element));
                                 break;
                             case 'XMPFocalLength':
                                 $v = self::rationalNum($element) . ' mm';
                                 break;
                             case 'XMPAperatureValue':
                             case 'XMPFNumber':
                                 $v = 'f/' . self::rationalNum($element);
                                 break;
                             case 'XMPExposureBiasValue':
                             case 'XMPGPSAltitude':
                                 $v = self::rationalNum($element);
                                 break;
                             case 'XMPGPSLatitude':
                             case 'XMPGPSLongitude':
                                 $n = explode(',', substr($element, 0, -1));
                                 $r = $n[0] + $n[1] / 60;
                                 $ref = strtoupper(substr($element, -1, 1));
                                 $v = Image::toDMS($r, $ref);
                                 if (in_array($ref, array('S', 'W'))) {
                                     $r = -$r;
                                 }
                                 $r = (double) $r;
                                 $image->set(substr($field, 3), $r);
                                 break;
                             case 'XMPLensInfo':
                                 preg_match_all('~(\\d+/\\d+)~', $v, $matches);
                                 if (isset($matches[1]) && !empty($matches[1])) {
                                     $lens = array();
                                     foreach ($matches[1] as $i => $f) {
                                         $term = explode('/', $f);
                                         if ($term[0] != 0 && $term[1] != 0) {
                                             $lens[$i] = convertToFraction($term[0] / $term[1]);
                                         } else {
                                             $lens[$i] = 0;
                                         }
                                     }
                                     if ($lens[0] == $lens[1]) {
                                         $v = sprintf('%0.0fmm', $lens[0]);
                                     } else {
                                         $v = sprintf('%0.0f-%0.0fmm', $lens[0], $lens[1]);
                                     }
                                     if ($lens[2] == $lens[3]) {
                                         if ($lens[2] != 0) {
                                             $v .= sprintf(' f/%0.1f', $lens[2]);
                                         }
                                     } else {
                                         $v .= sprintf(' f/%0.1f-%0.1f', $lens[3], $lens[2]);
                                     }
                                 }
                                 break;
                             case 'rating':
                                 $v = min(getoption('rating_stars_count'), $v) * min(1, getOption('rating_split_stars'));
                                 $image->set('total_value', $v);
                                 $image->set('total_votes', 1);
                                 break;
                             case 'XMPKeywords':
                                 if (!is_array($element)) {
                                     $element = explode(',', $element);
                                 }
                                 $element = array_unique(array_merge($image->getTags(), $element));
                                 $image->setTags($element);
                                 break;
                         }
                     }
                     $image->set($field, $v);
                 }
             }
             $image->save();
         }
     }
     return $image;
 }