function getImageMetadata($event)
 {
     $medium = $event->getArgument('medium');
     $data = array('headers' => null, 'exif' => null, 'xmp' => null, 'irb' => null, 'finfo' => null);
     $ext = $medium->getExtension();
     $file = $medium->getAbsPath();
     if (zmgFactory::getConfig()->get('plugins/jpeg_metadata/general/readwrite') && ($ext == "jpg" || $ext == "jpeg") && !ZMG_SAFEMODE_ON) {
         //import libs first (duh ;) )
         $jmt_dir = "v" . str_replace('.', '_', ZMG_JMT_VERSION);
         zmgimport('org.zoomfactory.var.plugins.jpeg_metadata.' . $jmt_dir . '.EXIF');
         //takes care of some deferred loading as well
         zmgimport('org.zoomfactory.var.plugins.jpeg_metadata.' . $jmt_dir . '.Photoshop_File_Info');
         // Retreive the EXIF, XMP and Photoshop IRB information from
         // the existing file, so that it can be updated later on...
         $data['headers'] = get_jpeg_header_data($file);
         $data['exif'] = get_EXIF_JPEG($file);
         $data['xmp'] = read_XMP_array_from_text(get_XMP_text($data['headers']));
         $data['irb'] = get_Photoshop_IRB($data['headers']);
         $data['finfo'] = get_photoshop_file_info($data['exif'], $data['xmp'], $data['irb']);
         // Check if there is a default for the date defined
         if (!array_key_exists('date', $data['finfo']) || array_key_exists('date', $data['finfo']) && $data['finfo']['date'] == '') {
             // No default for the date defined
             // figure out a default from the file
             // Check if there is a EXIF Tag 36867 "Date and Time of Original"
             if ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(34665, $data['exif'][0]) && array_key_exists(0, $data['exif'][0][34665]) && array_key_exists(36867, $data['exif'][0][34665][0])) {
                 // Tag "Date and Time of Original" found - use it for the default date
                 $data['finfo']['date'] = $data['exif'][0][34665][0][36867]['Data'][0];
                 $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
             } elseif ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(34665, $data['exif'][0]) && array_key_exists(0, $data['exif'][0][34665]) && array_key_exists(36868, $data['exif'][0][34665][0])) {
                 // Check if there is a EXIF Tag 36868 "Date and Time when Digitized"
                 // Tag "Date and Time when Digitized" found - use it for the default date
                 $data['finfo']['date'] = $data['exif'][0][34665][0][36868]['Data'][0];
                 $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
             } else {
                 if ($data['exif'] != false && array_key_exists(0, $data['exif']) && array_key_exists(306, $data['exif'][0])) {
                     // Check if there is a EXIF Tag 306 "Date and Time"
                     // Tag "Date and Time" found - use it for the default date
                     $data['finfo']['date'] = $data['exif'][0][306]['Data'][0];
                     $data['finfo']['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $data['finfo']['date']);
                 } else {
                     // Couldn't find an EXIF date in the image
                     // Set default date as creation date of file
                     $data['finfo']['date'] = date("Y-m-d", filectime($file));
                 }
             }
         }
     }
     return zmgJpeg_metadataPlugin::interpretImageData($data, $medium->filename);
 }
Exemple #2
0
/**
 * mime_image_get_exif_data fetch meta data from uploaded image
 *
 * @param array $pUpload uploaded file data
 * @access public
 * @return array filled with exif goodies
 */
function mime_image_get_exif_data($pUpload)
{
    $exifHash = array();
    if (function_exists('exif_read_data') && !empty($pUpload['source_file']) && is_file($pUpload['source_file']) && preg_match("#/(jpe?g|tiff)#i", $pUpload['type'])) {
        // exif_read_data can be noisy due to crappy files, e.g. "Incorrect APP1 Exif Identifier Code" etc...
        $exifHash = @exif_read_data($pUpload['source_file'], 0, TRUE);
        // extract more information if we can find it
        if (ini_get('short_open_tag')) {
            require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/JPEG.php';
            require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/JFIF.php';
            require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/PictureInfo.php';
            require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/XMP.php';
            require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/EXIF.php';
            // Retrieve the header information from the JPEG file
            $jpeg_header_data = get_jpeg_header_data($pUpload['source_file']);
            // Retrieve EXIF information from the JPEG file
            $Exif_array = get_EXIF_JPEG($pUpload['source_file']);
            // Retrieve XMP information from the JPEG file
            $XMP_array = read_XMP_array_from_text(get_XMP_text($jpeg_header_data));
            // Retrieve Photoshop IRB information from the JPEG file
            $IRB_array = get_Photoshop_IRB($jpeg_header_data);
            if (!empty($exifHash['IFD0']['Software']) && preg_match('/photoshop/i', $exifHash['IFD0']['Software'])) {
                require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/Photoshop_File_Info.php';
                // Retrieve Photoshop File Info from the three previous arrays
                $psFileInfo = get_photoshop_file_info($Exif_array, $XMP_array, $IRB_array);
                if (!empty($psFileInfo['headline'])) {
                    $exifHash['headline'] = $psFileInfo['headline'];
                }
                if (!empty($psFileInfo['caption'])) {
                    $exifHash['caption'] = $psFileInfo['caption'];
                }
            }
        }
        // only makes sense to store the GPS data if we at least have latitude and longitude
        if (!empty($exifHash['GPS'])) {
            // store GPS coordinates as deg decimal float
            $gpsConv = array('GPSLatitude', 'GPSDestLatitude', 'GPSLongitude', 'GPSDestLongitude');
            foreach ($gpsConv as $conv) {
                if (!empty($exifHash['GPS'][$conv]) && is_array($exifHash['GPS'][$conv])) {
                    $exifHash['GPS'][$conv] = mime_image_convert_exifgps($exifHash['GPS'][$conv]);
                }
            }
        }
    }
    return $exifHash;
}
Exemple #3
0
// i.e. $filename is defined, and $new_ps_file_info_array is not
if (!isset($new_ps_file_info_array) && isset($filename) && is_string($filename)) {
    // Hide any unknown EXIF tags
    $GLOBALS['HIDE_UNKNOWN_TAGS'] = TRUE;
    // Accessing the existing file info for the specified file requires these includes
    include 'JPEG.php';
    include 'XMP.php';
    include 'Photoshop_IRB.php';
    include 'EXIF.php';
    include 'Photoshop_File_Info.php';
    // Retrieve the header information from the JPEG file
    $jpeg_header_data = get_jpeg_header_data($filename);
    // Retrieve EXIF information from the JPEG file
    $Exif_array = get_EXIF_JPEG($filename);
    // Retrieve XMP information from the JPEG file
    $XMP_array = read_XMP_array_from_text(get_XMP_text($jpeg_header_data));
    // Retrieve Photoshop IRB information from the JPEG file
    $IRB_array = get_Photoshop_IRB($jpeg_header_data);
    // Retrieve Photoshop File Info from the three previous arrays
    $new_ps_file_info_array = get_photoshop_file_info($Exif_array, $XMP_array, $IRB_array);
    // Check if there is an array of defaults available
    if (isset($default_ps_file_info_array) && is_array($default_ps_file_info_array)) {
        // There are defaults defined
        // Check if there is a default for the date defined
        if (!array_key_exists('date', $default_ps_file_info_array) || array_key_exists('date', $default_ps_file_info_array) && $default_ps_file_info_array['date'] == '') {
            // No default for the date defined
            // figure out a default from the file
            // Check if there is a EXIF Tag 36867 "Date and Time of Original"
            if ($Exif_array != FALSE && array_key_exists(0, $Exif_array) && array_key_exists(34665, $Exif_array[0]) && array_key_exists(0, $Exif_array[0][34665]) && array_key_exists(36867, $Exif_array[0][34665][0])) {
                // Tag "Date and Time of Original" found - use it for the default date
                $default_ps_file_info_array['date'] = $Exif_array[0][34665][0][36867]['Data'][0];
 /**
  * extractMetaData extract meta data from images
  *
  * @param array $pParamHash
  * @param array $pFile
  * @access public
  * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
  * @deprecated deprecated since version 2.1.0-beta
  */
 function extractMetaData(&$pParamHash, &$pFile)
 {
     //deprecated( "This method has been replaced by a method in LibertyMime. Please try to migrate your code." );
     // Process a JPEG , jpeg_metadata_tk REQUIRES short_tags because that is the way it was written. feel free to fix something. XOXO spiderr
     if (ini_get('short_open_tag') && function_exists('exif_read_data') && !empty($pFile['tmp_name']) && strpos(strtolower($pFile['type']), 'jpeg') !== FALSE) {
         $exifHash = @exif_read_data($pFile['tmp_name'], 0, true);
         // Change: Allow this example file to be easily relocatable - as of version 1.11
         require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/JPEG.php';
         require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/JFIF.php';
         require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/PictureInfo.php';
         require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/XMP.php';
         require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/EXIF.php';
         // Retrieve the header information from the JPEG file
         $jpeg_header_data = get_jpeg_header_data($pFile['tmp_name']);
         // Retrieve EXIF information from the JPEG file
         $Exif_array = get_EXIF_JPEG($pFile['tmp_name']);
         // Retrieve XMP information from the JPEG file
         $XMP_array = read_XMP_array_from_text(get_XMP_text($jpeg_header_data));
         // Retrieve Photoshop IRB information from the JPEG file
         $IRB_array = get_Photoshop_IRB($jpeg_header_data);
         if (!empty($exifHash['IFD0']['Software']) && preg_match('/photoshop/i', $exifHash['IFD0']['Software'])) {
             require_once UTIL_PKG_PATH . 'jpeg_metadata_tk/Photoshop_File_Info.php';
             // Retrieve Photoshop File Info from the three previous arrays
             $psFileInfo = get_photoshop_file_info($Exif_array, $XMP_array, $IRB_array);
             if (!empty($psFileInfo['headline'])) {
                 if (empty($pParamHash['title'])) {
                     $pParamHash['title'] = $psFileInfo['headline'];
                 } elseif (empty($pParamHash['edit']) && !$this->getField('data') && $pParamHash['title'] != $psFileInfo['headline']) {
                     $pParamHash['edit'] = $psFileInfo['headline'];
                 }
             }
             if (!empty($psFileInfo['caption'])) {
                 if (empty($pParamHash['title'])) {
                     $pParamHash['title'] = $psFileInfo['caption'];
                 } elseif (empty($pParamHash['edit']) && !$this->getField('data') && $pParamHash['title'] != $psFileInfo['caption']) {
                     $pParamHash['edit'] = $psFileInfo['caption'];
                 }
             }
         }
         if (!empty($exifHash['EXIF']['DateTimeOriginal'])) {
             $pParamHash['event_time'] = strtotime($exifHash['EXIF']['DateTimeOriginal']);
         }
         if (!empty($exifHash['IFD0']['ImageDescription'])) {
             if (empty($pParamHash['title'])) {
                 $pParamHash['title'] = $exifHash['IFD0']['ImageDescription'];
             } elseif (empty($pParamHash['edit']) && !$this->getField('data') && $pParamHash['title'] != $exifHash['IFD0']['ImageDescription']) {
                 $pParamHash['edit'] = $exifHash['IFD0']['ImageDescription'];
             }
         }
     }
 }
 /**
  * Make a newly uploaded medium ready for use in the gallery.
  *
  * @param string $image
  * @param string $filename
  * @param string $filetype
  * @param string $keywords
  * @param string $name
  * @param string $descr
  * @param int $rotate
  * @param int $degrees
  * @param int $ignoresizes
  * @return boolean
  * @access public
  */
 function processImage($image, $filename, $filetype, $keywords, $name, $descr, $rotate, $degrees = 0, $ignoresizes = 0)
 {
     global $mosConfig_absolute_path, $zoom;
     // reset script execution time limit (as set in MAX_EXECUTION_TIME ini directive)...
     // requires SAFE MODE to be OFF!
     if (ini_get('safe_mode') != 1) {
         set_time_limit(0);
     }
     $imagepath = $zoom->_CONFIG['imagepath'];
     $catdir = $zoom->_gallery->getDir();
     $filename = urldecode($filename);
     // replace every space-character with a single "_"
     $filename = ereg_replace(" ", "_", $filename);
     $filename = stripslashes($filename);
     $filename = ereg_replace("'", "_", $filename);
     // Get rid of extra underscores
     $filename = ereg_replace("_+", "_", $filename);
     $filename = ereg_replace("(^_|_\$)", "", $filename);
     $zoom->checkDuplicate($filename, 'filename');
     $filename = $zoom->_tempname;
     // replace space-characters in combination with a comma with 'air'...or nothing!
     $keywords = $zoom->cleanString($keywords);
     //$keywords = $zoom->htmlnumericentities($keywords);
     $name = $zoom->cleanString($name);
     //$name = $zoom->htmlnumericentities($name);
     //$descr = $zoom->cleanString($descr);
     //$descr = $zoom->htmlnumericentities($descr);
     if (empty($name)) {
         $name = $zoom->_CONFIG['tempName'];
     }
     $imgobj = new image(0);
     //create a new image object with a foo imgid
     $imgobj->setImgInfo($filename, $name, $keywords, $descr, $zoom->_gallery->_id, $zoom->currUID, 1, 1);
     $imgobj->getMimeType($filetype, $image);
     unset($filename, $name, $keywords, $descr);
     //clear memory, just in case...
     if (!$zoom->acceptableSize($image)) {
         // the file is simply too big, register this...
         $this->_err_num++;
         $this->_err_names[$this->_err_num] = $imgobj->_filename;
         $this->_err_types[$this->_err_num] = sprintf(_ZOOM_ALERT_TOOBIG, $zoom->_CONFIG['maxsizekb'] . 'kB');
         return false;
     }
     /* IMPORTANT CHEATSHEET:
     	     * If we don't get useful data from that or its a type we don't
     	     * recognize, take a swing at it using the file name.
     	    if ($mimeType == 'application/octet-stream' ||
     		    $mimeType == 'application/unknown' ||
     		    GalleryCoreApi::convertMimeToExtension($mimeType) == null) {
     		$extension = GalleryUtilities::getFileExtension($file['name']);
     		$mimeType = GalleryCoreApi::convertExtensionToMime($extension);
     	    }
     	    */
     if ($zoom->acceptableFormat($imgobj->getMimeType(), true)) {
         // File is an image/ movie/ document...
         $file = "{$mosConfig_absolute_path}/{$imagepath}{$catdir}/" . $imgobj->_filename;
         $desfile = "{$mosConfig_absolute_path}/{$imagepath}{$catdir}/thumbs/" . $imgobj->_filename;
         if (is_uploaded_file($image)) {
             if (!move_uploaded_file("{$image}", $file)) {
                 // some error occured while moving file, register this...
                 $this->_err_num++;
                 $this->_err_names[$this->_err_num] = $imgobj->_filename;
                 $this->_err_types[$this->_err_num] = _ZOOM_ALERT_MOVEFAILURE;
                 return false;
             }
         } elseif (!$zoom->platform->copy("{$image}", $file) && !$zoom->platform->file_exists($file)) {
             // some error occured while moving file, register this...
             $this->_err_num++;
             $this->_err_names[$this->_err_num] = $imgobj->_filename;
             $this->_err_types[$this->_err_num] = _ZOOM_ALERT_MOVEFAILURE;
             return false;
         }
         @$zoom->platform->chmod($file, '0777');
         $viewsize = $mosConfig_absolute_path . "/" . $imagepath . $catdir . "/viewsize/" . $imgobj->_filename;
         if ($zoom->acceptableFormat($imgobj->getMimeType(), true)) {
             if ($zoom->isImage($imgobj->getMimeType(), true)) {
                 $imgobj->_size = $zoom->platform->getimagesize($file);
                 // get image EXIF & IPTC data from file to save it in viewsize image and get a thumbnail...
                 if ($zoom->_CONFIG['readEXIF'] && ($imgobj->_type === "jpg" || $imgobj->_type === "jpeg") && !(bool) ini_get('safe_mode')) {
                     // Retreive the EXIF, XMP and Photoshop IRB information from
                     // the existing file, so that it can be updated later on...
                     $jpeg_header_data = get_jpeg_header_data($file);
                     $EXIF_data = get_EXIF_JPEG($file);
                     $XMP_data = read_XMP_array_from_text(get_XMP_text($jpeg_header_data));
                     $IRB_data = get_Photoshop_IRB($jpeg_header_data);
                     $new_ps_file_info = get_photoshop_file_info($EXIF_data, $XMP_data, $IRB_data);
                     // Check if there is a default for the date defined
                     if (!array_key_exists('date', $new_ps_file_info) || array_key_exists('date', $new_ps_file_info) && $new_ps_file_info['date'] == '') {
                         // No default for the date defined
                         // figure out a default from the file
                         // Check if there is a EXIF Tag 36867 "Date and Time of Original"
                         if ($EXIF_data != FALSE && array_key_exists(0, $EXIF_data) && array_key_exists(34665, $EXIF_data[0]) && array_key_exists(0, $EXIF_data[0][34665]) && array_key_exists(36867, $EXIF_data[0][34665][0])) {
                             // Tag "Date and Time of Original" found - use it for the default date
                             $new_ps_file_info['date'] = $EXIF_data[0][34665][0][36867]['Data'][0];
                             $new_ps_file_info['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $new_ps_file_info['date']);
                         } elseif ($EXIF_data != FALSE && array_key_exists(0, $EXIF_data) && array_key_exists(34665, $EXIF_data[0]) && array_key_exists(0, $EXIF_data[0][34665]) && array_key_exists(36868, $EXIF_data[0][34665][0])) {
                             // Check if there is a EXIF Tag 36868 "Date and Time when Digitized"
                             // Tag "Date and Time when Digitized" found - use it for the default date
                             $new_ps_file_info['date'] = $EXIF_data[0][34665][0][36868]['Data'][0];
                             $new_ps_file_info['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $new_ps_file_info['date']);
                         } else {
                             if ($EXIF_data != FALSE && array_key_exists(0, $EXIF_data) && array_key_exists(306, $EXIF_data[0])) {
                                 // Check if there is a EXIF Tag 306 "Date and Time"
                                 // Tag "Date and Time" found - use it for the default date
                                 $new_ps_file_info['date'] = $EXIF_data[0][306]['Data'][0];
                                 $new_ps_file_info['date'] = preg_replace("/(\\d\\d\\d\\d):(\\d\\d):(\\d\\d)( \\d\\d:\\d\\d:\\d\\d)/", "\$1-\$2-\$3", $new_ps_file_info['date']);
                             } else {
                                 // Couldn't find an EXIF date in the image
                                 // Set default date as creation date of file
                                 $new_ps_file_info['date'] = date("Y-m-d", filectime($file));
                             }
                         }
                     }
                 }
                 // First, rotate the image (if that's mentioned in the 'job description')...
                 if ($rotate) {
                     $tmpdir = $mosConfig_absolute_path . "/" . $zoom->createTempDir();
                     $new_source = $tmpdir . "/" . $imgobj->_filename;
                     if (!$this->rotateImage($file, $new_source, $degrees, $imgobj)) {
                         $this->_err_num++;
                         $this->_err_names[$this->_err_num] = $imgobj->_filename;
                         $this->_err_types[$this->_err_num] = "Error rotating image";
                         return false;
                     } else {
                         @$zoom->platform->unlink($file);
                         if ($zoom->platform->copy($new_source, $file)) {
                             $imgobj->_size = $zoom->platform->getimagesize($file);
                         }
                     }
                 }
                 // resize to thumbnail...
                 // 1-31-2006: fix #0000151
                 if (!$zoom->platform->file_exists($desfile)) {
                     if (!$this->resizeImage($file, $desfile, $zoom->_CONFIG['size'], $imgobj)) {
                         $this->_err_num++;
                         $this->_err_names[$this->_err_num] = $imgobj->_filename;
                         $this->_err_types[$this->_err_num] = _ZOOM_ALERT_IMGERROR;
                         return false;
                     }
                 }
                 // if the image size is greater than the given maximum: resize it!
                 if (!$zoom->platform->file_exists($viewsize)) {
                     //If the image is larger than the max size
                     if (($imgobj->_size[0] > $zoom->_CONFIG['maxsize'] || $imgobj->_size[1] > $zoom->_CONFIG['maxsize']) && !$ignoresizes) {
                         //Resizes the file. If successful, continue
                         if ($this->resizeImage($file, $viewsize, $zoom->_CONFIG['maxsize'], $imgobj)) {
                             //Watermark?
                             if ((bool) $zoom->_CONFIG['wm_apply']) {
                                 //Watermark. Return errors if not successuful
                                 if (!$this->watermarkImage($viewsize, $viewsize, $imgobj)) {
                                     $this->_err_num++;
                                     $this->_err_names[$this->_err_num] = $imgobj->_filename;
                                     $this->_err_types[$this->_err_num] = _ZOOM_ALERT_WATERMARKERROR;
                                     return false;
                                 }
                             }
                         } else {
                             $this->_err_num++;
                             $this->_err_names[$this->_err_num] = $imgobj->_filename;
                             $this->_err_types[$this->_err_num] = _ZOOM_ALERT_IMGERROR;
                             return false;
                         }
                     } else {
                         //Watermark?
                         if ((bool) $zoom->_CONFIG['wm_apply']) {
                             //Watermark. Return errors if not successuful
                             if (!$this->watermarkImage($file, $file, $imgobj)) {
                                 $this->_err_num++;
                                 $this->_err_names[$this->_err_num] = $imgobj->_filename;
                                 $this->_err_types[$this->_err_num] = _ZOOM_ALERT_WATERMARKERROR;
                                 return false;
                             }
                         }
                     }
                 }
             } elseif ($zoom->isDocument($imgobj->getMimeType(), true)) {
                 if ($zoom->isIndexable($imgobj->getMimeType(), true) && $this->_use_PDF) {
                     if (!$this->indexDocument($file, $imgobj->_filename)) {
                         $this->_err_num++;
                         $this->_err_names[$this->_err_num] = $imgobj->_filename;
                         $this->_err_types[$this->_err_num] = _ZOOM_ALERT_INDEXERROR;
                         return false;
                     }
                 } else {
                     if ($zoom->platform->copy($file, $viewsize)) {
                         if ((bool) $zoom->_CONFIG['wm_apply']) {
                             // put a watermark on the source image...
                             if (!$this->watermarkImage($viewsize, $viewsize, $imgobj)) {
                                 $this->_err_num++;
                                 $this->_err_names[$this->_err_num] = $imgobj->_filename;
                                 $this->_err_types[$this->_err_num] = _ZOOM_ALERT_WATERMARKERROR;
                                 return false;
                             }
                         }
                     } else {
                         // some error occured while moving file, register this...
                         $this->_err_num++;
                         $this->_err_names[$this->_err_num] = $imgobj->_filename;
                         $this->_err_types[$this->_err_num] = _ZOOM_ALERT_MOVEFAILURE;
                         return false;
                     }
                 }
             } elseif ($zoom->isMovie($imgobj->getMimeType(), true)) {
                 //if movie is 'thumbnailable' -> make a thumbnail then!
                 if ($zoom->isThumbnailable($imgobj->_type) && $this->_use_FFMPEG) {
                     if (!$this->createMovieThumb($file, $zoom->_CONFIG['size'], $imgobj->_filename)) {
                         $this->_err_num++;
                         $this->_err_names[$this->_err_num] = $imgobj->_filename;
                         $this->_err_types[$this->_err_num] = _ZOOM_ALERT_IMGERROR;
                         return false;
                     }
                 }
             } elseif ($zoom->isAudio($imgobj->getMimeType(), true)) {
                 // TODO: indexing audio files (mp3-files, etc.) properties, e.g. id3vX tags...
             }
             if (!$imgobj->save()) {
                 $this->_err_num++;
                 $this->_err_names[$this->_err_num] = $imgobj->_filename;
                 $this->_err_types[$this->_err_num] = "Database failure";
             }
         }
     } else {
         //Not the right format, register this...
         $this->_err_num++;
         $this->_err_names[$this->_err_num] = $imgobj->_filename;
         $this->_err_types[$this->_err_num] = _ZOOM_ALERT_WRONGFORMAT_MULT;
         return false;
     }
     return true;
 }
Exemple #6
0
        <BR>
        <HR>
        <BR>

        Output the EXIF Information -->
        <?php 
echo Interpret_EXIF_to_HTML(get_EXIF_JPEG($filename), $filename);
?>

        <BR>
        <HR>
        <BR>

        Output the XMP Information -->
        <?php 
echo Interpret_XMP_to_HTML(read_XMP_array_from_text(get_XMP_text($jpeg_header_data)));
?>

        <BR>
        <HR>
        <BR>

        Output the Photoshop IRB (including the IPTC-NAA info -->
        <?php 
echo Interpret_IRB_to_HTML(get_Photoshop_IRB($jpeg_header_data), $filename);
?>

        <BR>
        <HR>
        <BR>
Exemple #7
0
function read_IFD_universal($filehnd, $Tiff_offset, $Byte_Align, $Tag_Definitions_Name, $local_offsets = FALSE, $read_next_ptr = TRUE)
{
    if ($filehnd == NULL || feof($filehnd)) {
        return array(FALSE, 0);
    }
    // Record the Name of the Tag Group used for this IFD in the output array
    $OutputArray['Tags Name'] = $Tag_Definitions_Name;
    // Record the offset of the TIFF header in the output array
    $OutputArray['Tiff Offset'] = $Tiff_offset;
    // First 2 bytes of IFD are number of entries in the IFD
    $No_Entries_str = network_safe_fread($filehnd, 2);
    $No_Entries = get_IFD_Data_Type($No_Entries_str, 3, $Byte_Align);
    // If the data is corrupt, the number of entries may be huge, which will cause errors
    // This is often caused by a lack of a Next-IFD pointer
    if ($No_Entries > 10000) {
        // Huge number of entries - abort
        echo "<p>Error: huge number of EXIF entries - EXIF is probably Corrupted</p>\n";
        return array(FALSE, 0);
    }
    // If the data is corrupt or just stupid, the number of entries may zero,
    // Indicate this by returning false
    if ($No_Entries === 0) {
        // No entries - abort
        return array(FALSE, 0);
    }
    // Save the file position where first IFD record starts as non-standard offsets
    // need to know this to calculate an absolute offset
    $IFD_first_rec_pos = ftell($filehnd);
    // Read in the IFD structure
    $IFD_Data = network_safe_fread($filehnd, 12 * $No_Entries);
    // Check if the entire IFD was able to be read
    if (strlen($IFD_Data) != 12 * $No_Entries) {
        // Couldn't read the IFD Data properly, Some Casio files have no Next IFD pointer, hence cause this error
        echo "<p>Error: EXIF Corrupted</p>\n";
        return array(FALSE, 0);
    }
    // Last 4 bytes of a standard IFD are the offset to the next IFD
    // Some NON-Standard IFD implementations do not have this, hence causing problems if it is read
    // If the Next IFD pointer has been requested to be read,
    if ($read_next_ptr) {
        // Read the pointer to the next IFD
        $Next_Offset_str = network_safe_fread($filehnd, 4);
        $Next_Offset = get_IFD_Data_Type($Next_Offset_str, 4, $Byte_Align);
    } else {
        // Otherwise set the pointer to zero ( no next IFD )
        $Next_Offset = 0;
    }
    // Initialise current position to the start
    $pos = 0;
    // Loop for reading IFD entries
    for ($i = 0; $i < $No_Entries; $i++) {
        // First 2 bytes of IFD entry are the tag number ( Unsigned Short )
        $Tag_No_str = substr($IFD_Data, $pos, 2);
        $Tag_No = get_IFD_Data_Type($Tag_No_str, 3, $Byte_Align);
        $pos += 2;
        // Next 2 bytes of IFD entry are the data format ( Unsigned Short )
        $Data_Type_str = substr($IFD_Data, $pos, 2);
        $Data_Type = get_IFD_Data_Type($Data_Type_str, 3, $Byte_Align);
        $pos += 2;
        // If Datatype is not between 1 and 12, then skip this entry, it is probably corrupted or custom
        if ($Data_Type > 12 || $Data_Type < 1) {
            $pos += 8;
            continue 1;
            // Stop trying to process the tag any further and skip to the next one
        }
        // Next 4 bytes of IFD entry are the data count ( Unsigned Long )
        $Data_Count_str = substr($IFD_Data, $pos, 4);
        $Data_Count = get_IFD_Data_Type($Data_Count_str, 4, $Byte_Align);
        $pos += 4;
        if ($Data_Count > 100000) {
            echo "<p>Error: huge EXIF data count - EXIF is probably Corrupted</p>\n";
            // Some Casio files have no Next IFD pointer, hence cause errors
            return array(FALSE, 0);
        }
        // Total Data size is the Data Count multiplied by the size of the Data Type
        $Total_Data_Size = $GLOBALS['IFD_Data_Sizes'][$Data_Type] * $Data_Count;
        $Data_Start_pos = -1;
        // If the total data size is larger than 4 bytes, then the data part is the offset to the real data
        if ($Total_Data_Size > 4) {
            // Not enough room for data - offset provided instead
            $Data_Offset_str = substr($IFD_Data, $pos, 4);
            $Data_Start_pos = get_IFD_Data_Type($Data_Offset_str, 4, $Byte_Align);
            // In some NON-STANDARD makernotes, the offset is relative to the start of the current IFD entry
            if ($local_offsets) {
                // This is a NON-Standard IFD, seek relative to the start of the current tag
                fseek($filehnd, $IFD_first_rec_pos + $pos - 8 + $Data_Start_pos);
            } else {
                // This is a normal IFD, seek relative to the start of the TIFF header
                fseek($filehnd, $Tiff_offset + $Data_Start_pos);
            }
            // Read the data block from the offset position
            $DataStr = network_safe_fread($filehnd, $Total_Data_Size);
        } else {
            // The data block is less than 4 bytes, and is provided in the IFD entry, so read it
            $DataStr = substr($IFD_Data, $pos, $Total_Data_Size);
        }
        // Increment the position past the data
        $pos += 4;
        // Now create the entry for output array
        $Data_Array = array();
        // Read the data items from the data block
        if ($Data_Type != 2 && $Data_Type != 7) {
            // The data type is Numerical, Read the data items from the data block
            for ($j = 0; $j < $Data_Count; $j++) {
                $Part_Data_Str = substr($DataStr, $j * $GLOBALS['IFD_Data_Sizes'][$Data_Type], $GLOBALS['IFD_Data_Sizes'][$Data_Type]);
                $Data_Array[] = get_IFD_Data_Type($Part_Data_Str, $Data_Type, $Byte_Align);
            }
        } elseif ($Data_Type == 2) {
            // The data type is String(s)   (type 2)
            // Strip the last terminating Null
            $DataStr = substr($DataStr, 0, strlen($DataStr) - 1);
            // Split the data block into multiple strings whereever there is a Null
            $Data_Array = explode("", $DataStr);
        } else {
            // The data type is Unknown (type 7)
            // Do nothing to data
            $Data_Array = $DataStr;
        }
        // If this is a Sub-IFD entry,
        if (array_key_exists($Tag_No, $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name]) && "SubIFD" == $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No]['Type']) {
            // This is a Sub-IFD entry, go and process the data forming Sub-IFD and use its output array as the new data for this entry
            fseek($filehnd, $Tiff_offset + $Data_Array[0]);
            $Data_Array = read_Multiple_IFDs($filehnd, $Tiff_offset, $Byte_Align, $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No]['Tags Name']);
        }
        $desc = "";
        $units = "";
        // Check if this tag exists in the list of tag definitions,
        if (array_key_exists($Tag_No, $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name])) {
            if (array_key_exists('Description', $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No])) {
                $desc = $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No]['Description'];
            }
            if (array_key_exists('Units', $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No])) {
                $units = $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No]['Units'];
            }
            // Tag exists in definitions, append details to output array
            $OutputArray[$Tag_No] = array("Tag Number" => $Tag_No, "Tag Name" => $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No]['Name'], "Tag Description" => $desc, "Data Type" => $Data_Type, "Type" => $GLOBALS["IFD_Tag_Definitions"][$Tag_Definitions_Name][$Tag_No]['Type'], "Units" => $units, "Data" => $Data_Array);
        } else {
            // Tag doesnt exist in definitions, append unknown details to output array
            $OutputArray[$Tag_No] = array("Tag Number" => $Tag_No, "Tag Name" => "Unknown Tag #" . $Tag_No, "Tag Description" => "", "Data Type" => $Data_Type, "Type" => "Unknown", "Units" => "", "Data" => $Data_Array);
        }
        // Some information of type "Unknown" (type 7) might require information about
        // how it's position and byte alignment in order to be decoded
        if ($Data_Type == 7) {
            $OutputArray[$Tag_No]['Offset'] = $Data_Start_pos;
            $OutputArray[$Tag_No]['Byte Align'] = $Byte_Align;
        }
        ////////////////////////////////////////////////////////////////////////
        // Special Data handling
        ////////////////////////////////////////////////////////////////////////
        // Check if this is a Print Image Matching entry
        if ($OutputArray[$Tag_No]['Type'] == "PIM") {
            // This is a Print Image Matching entry, decode it.
            $OutputArray[$Tag_No] = Decode_PIM($OutputArray[$Tag_No], $Tag_Definitions_Name);
        }
        // Interpret the entry into a text string using a custom interpreter
        $text_val = get_Tag_Text_Value($OutputArray[$Tag_No], $Tag_Definitions_Name);
        // Check if a text string was generated
        if ($text_val !== FALSE) {
            // A string was generated, append it to the output array entry
            $OutputArray[$Tag_No]['Text Value'] = $text_val;
            $OutputArray[$Tag_No]['Decoded'] = TRUE;
        } else {
            // A string was NOT generated, append a generic string to the output array entry
            $OutputArray[$Tag_No]['Text Value'] = get_IFD_value_as_text($OutputArray[$Tag_No]) . " " . $units;
            $OutputArray[$Tag_No]['Decoded'] = FALSE;
        }
        // Check if this entry is the Maker Note
        if ($Tag_Definitions_Name == "EXIF" && $Tag_No == 37500) {
            // Save some extra information which will allow Makernote Decoding with the output array entry
            $OutputArray[$Tag_No]['Offset'] = $Data_Start_pos;
            $OutputArray[$Tag_No]['Tiff Offset'] = $Tiff_offset;
            $OutputArray[$Tag_No]['ByteAlign'] = $Byte_Align;
            // Save a pointer to this entry for Maker note processing later
            $GLOBALS["Maker_Note_Tag"] =& $OutputArray[$Tag_No];
        }
        // Check if this is a IPTC/NAA Record within the EXIF IFD
        if (($Tag_Definitions_Name == "EXIF" || $Tag_Definitions_Name == "TIFF") && $Tag_No == 33723) {
            // This is a IPTC/NAA Record, interpret it and put result in the data for this entry
            $OutputArray[$Tag_No]['Data'] = get_IPTC($DataStr);
            $OutputArray[$Tag_No]['Decoded'] = TRUE;
        }
        // Change: Check for embedded XMP as of version 1.11
        // Check if this is a XMP Record within the EXIF IFD
        if (($Tag_Definitions_Name == "EXIF" || $Tag_Definitions_Name == "TIFF") && $Tag_No == 700) {
            // This is a XMP Record, interpret it and put result in the data for this entry
            $OutputArray[$Tag_No]['Data'] = read_XMP_array_from_text($DataStr);
            $OutputArray[$Tag_No]['Decoded'] = TRUE;
        }
        // Change: Check for embedded IRB as of version 1.11
        // Check if this is a Photoshop IRB Record within the EXIF IFD
        if (($Tag_Definitions_Name == "EXIF" || $Tag_Definitions_Name == "TIFF") && $Tag_No == 34377) {
            // This is a Photoshop IRB Record, interpret it and put result in the data for this entry
            $OutputArray[$Tag_No]['Data'] = unpack_Photoshop_IRB_Data($DataStr);
            $OutputArray[$Tag_No]['Decoded'] = TRUE;
        }
        // Exif Thumbnail
        // Check that both the thumbnail length and offset entries have been processed,
        // and that this is one of them
        if (($Tag_No == 513 && array_key_exists(514, $OutputArray) || $Tag_No == 514 && array_key_exists(513, $OutputArray)) && $Tag_Definitions_Name == "TIFF") {
            // Seek to the start of the thumbnail using the offset entry
            fseek($filehnd, $Tiff_offset + $OutputArray[513]['Data'][0]);
            // Read the thumbnail data, and replace the offset data with the thumbnail
            $OutputArray[513]['Data'] = network_safe_fread($filehnd, $OutputArray[514]['Data'][0]);
        }
        // Casio Thumbnail
        // Check that both the thumbnail length and offset entries have been processed,
        // and that this is one of them
        if (($Tag_No == 0x4 && array_key_exists(0x3, $OutputArray) || $Tag_No == 0x3 && array_key_exists(0x4, $OutputArray)) && $Tag_Definitions_Name == "Casio Type 2") {
            // Seek to the start of the thumbnail using the offset entry
            fseek($filehnd, $Tiff_offset + $OutputArray[0x4]['Data'][0]);
            // Read the thumbnail data, and replace the offset data with the thumbnail
            $OutputArray[0x4]['Data'] = network_safe_fread($filehnd, $OutputArray[0x3]['Data'][0]);
        }
        // Minolta Thumbnail
        // Check that both the thumbnail length and offset entries have been processed,
        // and that this is one of them
        if (($Tag_No == 0x88 && array_key_exists(0x89, $OutputArray) || $Tag_No == 0x89 && array_key_exists(0x88, $OutputArray)) && $Tag_Definitions_Name == "Olympus") {
            // Seek to the start of the thumbnail using the offset entry
            fseek($filehnd, $Tiff_offset + $OutputArray[0x88]['Data'][0]);
            // Read the thumbnail data, and replace the offset data with the thumbnail
            $OutputArray[0x88]['Data'] = network_safe_fread($filehnd, $OutputArray[0x89]['Data'][0]);
            // Sometimes the minolta thumbnail data is empty (or the offset is corrupt, which results in the same thing)
            // Check if the thumbnail data exists
            if ($OutputArray[0x88]['Data'] != "") {
                // Thumbnail exists
                // Minolta Thumbnails are missing their first 0xFF for some reason,
                // which is replaced with some weird character, so fix this
                $OutputArray[0x88]['Data'][0] = "ÿ";
            } else {
                // Thumbnail doesnt exist - make it obvious
                $OutputArray[0x88]['Data'] = FALSE;
            }
        }
    }
    // Return the array of IFD entries and the offset to the next IFD
    return array($OutputArray, $Next_Offset);
}
Exemple #8
0
 /**
  * function to update image metadata
  */
 function metadata_image($metadata_conf)
 {
     if (is_array($metadata_conf) && count($metadata_conf) > 0) {
         include_once 'metadata/Toolkit_Version.php';
         error_reporting(0);
         include_once 'metadata/JPEG.php';
         include_once 'metadata/XMP.php';
         include_once 'metadata/Photoshop_IRB.php';
         include_once 'metadata/EXIF.php';
         include_once 'metadata/Photoshop_File_Info.php';
         // Copy all of the HTML Posted variables into an array
         //$new_ps_file_info_array = $GLOBALS['HTTP_POST_VARS'];
         $new_ps_file_info_array = $metadata_conf;
         $filename = $new_ps_file_info_array['filename'];
         //echo $filename;
         // Protect against hackers editing other files
         $path_parts = pathinfo($filename);
         $array_extention = array('png', 'jpg');
         if (strcasecmp($path_parts["extension"], "jpg") != 0) {
             //if (!in_array($path_parts["extension"], $array_extention))
             #echo "Incorrect File Type - JPEG Only\n";
             return array('status' => 'failed', 'message' => 'Incorrect File Type - JPEG Only');
             exit;
         }
         // Change: removed limitation on file being in current directory - as of version 1.11
         // Retrieve the header information
         $jpeg_header_data = get_jpeg_header_data($filename);
         // Retreive the EXIF, XMP and Photoshop IRB information from
         // the existing file, so that it can be updated
         $Exif_array = get_EXIF_JPEG($filename);
         $XMP_array = read_XMP_array_from_text(get_XMP_text($jpeg_header_data));
         $IRB_array = get_Photoshop_IRB($jpeg_header_data);
         // Update the JPEG header information with the new Photoshop File Info
         $jpeg_header_data = put_photoshop_file_info($jpeg_header_data, $new_ps_file_info_array, $Exif_array, $XMP_array, $IRB_array);
         // Check if the Update worked
         if ($jpeg_header_data == FALSE) {
             //echo '$jpeg_header_data false';
             return array('status' => 'failed', 'message' => 'Error - Failure update Photoshop File Info : ' . $filename);
             // Abort processing
             exit;
         }
         // Attempt to write the new JPEG file
         if (FALSE == put_jpeg_header_data($filename, $filename, $jpeg_header_data)) {
             //echo 'put_jpeg_header_data false';
             return array('status' => 'failed', 'message' => 'Error - Failure to write new JPEG : ' . $filename);
             // Abort processing
             exit;
         }
         return array('status' => 'succes', 'message' => $filename . ' updated');
     }
 }
 /**
  * performs the service processing
  *
  * @param	string		Content which should be processed.
  * @param	string		Content type
  * @param	array		Configuration array
  * @return	boolean
  */
 function process($content = '', $type = '', $conf = array())
 {
     $this->conf = $conf;
     $this->out = array();
     if ($content) {
         $this->setInput($content, $type);
     }
     if ($inputFile = $this->getInputFile() and $jpeg_header_data = get_jpeg_header_data($inputFile)) {
         $this->xmpRaw = get_XMP_text($jpeg_header_data);
         preg_match('#<x:xmpmeta[^>]*>.*</x:xmpmeta>#is', $this->xmpRaw, $match);
         $this->xmpRaw = $match[0];
         $this->xmp = parseXMP2simpleArray(read_XMP_array_from_text($this->xmpRaw));
         foreach ($this->xmp as $key => $value) {
             // ignore empty lines headers and emtpy entries
             if ($value) {
                 switch (strtolower($key)) {
                     case 'dc:creator':
                         $this->out['fields']['creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:description':
                         $this->out['fields']['description'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:rights':
                         $this->out['fields']['copyright'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:subject':
                         $this->out['fields']['keywords'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'dc:title':
                         $this->out['fields']['title'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'iptc4xmpcore:countrycode':
                         if (strlen($value) == 2) {
                             $select = 'cn_iso_3';
                             $table = 'static_countries';
                             $where = tx_staticinfotables_div::getIsoCodeField($table, $value) . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr(strtoupper($value), 'static_countries');
                             $where .= t3lib_BEfunc::deleteClause($table);
                             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where);
                             if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                 $this->out['fields']['loc_country'] = $row['cn_iso_3'];
                             }
                         }
                         break;
                     case 'iptc4xmpcore:location':
                         $value = trim($value);
                         if ($value[0] == '/' or $value[0] == '\\') {
                             $this->out['fields']['file_orig_location'] = tx_svmetaextract_lib::forceUtf8($value);
                         } else {
                             $this->out['fields']['loc_desc'] = tx_svmetaextract_lib::forceUtf8($value);
                         }
                         break;
                     case 'xmp:createdate':
                         $this->out['fields']['date_cr'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xmp:creatortool':
                         $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xmp:modifydate':
                         $this->out['fields']['date_mod'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xap:createdate':
                         $this->out['fields']['date_cr'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xap:creatortool':
                         $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xap:modifydate':
                         $this->out['fields']['date_mod'] = tx_svmetaextract_lib::parseDate($value);
                         break;
                     case 'xaprights:copyright':
                         $this->out['fields']['copyright'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xaprights:usageterms':
                         $this->out['fields']['instructions'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'xmptpg:npages':
                         $this->out['fields']['pages'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'pdf:keywords':
                         $this->out['fields']['keywords'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'pdf:producer':
                         $this->out['fields']['file_creator'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:captionwriter':
                         $this->out['fields']['photoshop:captionwriter'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:city':
                         $this->out['fields']['loc_city'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:credit':
                         $this->out['fields']['copyright'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:headline':
                         $this->out['fields']['title'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                     case 'photoshop:instructions':
                         $this->out['fields']['instructions'] = tx_svmetaextract_lib::forceUtf8($value);
                         break;
                 }
             }
         }
         $this->out['fields']['meta']['xmp'] = $this->xmp;
         $this->out['fields']['meta']['xmp_xml'] = $this->xmpRaw;
     } else {
         $this->errorPush(T3_ERR_SV_NO_INPUT, 'No or empty input.');
     }
     return $this->getLastError();
 }