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
function write_copy_protection($outputfilename, $copystatus)
{
    $new_ps_file_info_array = array('title' => "", 'author' => "Hamsterpaj.net", 'authorsposition' => "", 'caption' => "", 'captionwriter' => $_SESSION['login']['id'], 'jobname' => "", 'copyrightstatus' => $copystatus, 'copyrightnotice' => "", 'ownerurl' => "", 'keywords' => array(), 'category' => "", 'supplementalcategories' => array(), 'date' => date("Y-m-d"), 'city' => "", 'state' => "", 'country' => "", 'credit' => "", 'source' => "", 'headline' => "", 'instructions' => "", 'transmissionreference' => "", 'urgency' => "");
    foreach ($new_ps_file_info_array as $var_key => $var_val) {
        $new_ps_file_info_array[$var_key] = stripslashes($var_val);
    }
    // Keywords should be an array - explode it on newline boundarys
    $new_ps_file_info_array['keywords'] = explode("\n", trim($new_ps_file_info_array['keywords']));
    // Supplemental Categories should be an array - explode it on newline boundarys
    $new_ps_file_info_array['supplementalcategories'] = explode("\n", trim($new_ps_file_info_array['supplementalcategories']));
    // Protect against hackers editing other files
    $path_parts = pathinfo($outputfilename);
    if (strcasecmp($path_parts["extension"], "jpg") != 0) {
        return "Incorrect File Type - JPEG Only\n";
        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($outputfilename);
    // 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);
    // Check if the Update worked
    if ($jpeg_header_data == FALSE) {
        // Update of file info didn't work - output error message
        return "Error - Failure update File Info : {$outputfilenam} <br>\n";
        exit;
    }
    // Attempt to write the new JPEG file
    if (FALSE == put_jpeg_header_data($outputfilename, $outputfilename, $jpeg_header_data)) {
        // Writing of the new file didn't work - output error message
        return "Error - Failure to write new JPEG : {$filename} <br>\n";
        // Abort processing
        exit;
    }
    //return "<p><a href=\"Edit_File_Info_Example.php?jpeg_fname=$outputfilename\" >View Full Metatdata Information</a></p>\n";
}
Exemple #3
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 #4
0
 * ************************************************************************* */
include 'Toolkit_Version.php';
// Change: added as of version 1.11
// Check for operation modes 2 or 3
// 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
 /**
  * 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 #7
0
function get_Meta_JPEG($filename)
{
    // Change: Added as of version 1.11
    // Check if a wrapper is being used - these are not currently supported (see notes at top of file)
    if (stristr($filename, "http://") != FALSE || stristr($filename, "ftp://") != FALSE) {
        // A HTTP or FTP wrapper is being used - show a warning and abort
        echo "HTTP and FTP wrappers are currently not supported with Meta - See EXIF/Meta functionality documentation - a local file must be specified<br>";
        echo "To work on an internet file, copy it locally to start with:<br><br>\n";
        echo "\$newfilename = tempnam ( \$dir, \"tmpmeta\" );<br>\n";
        echo "copy ( \"http://whatever.com\", \$newfilename );<br><br>\n";
        return FALSE;
    }
    // get the JPEG headers
    $jpeg_header_data = get_jpeg_header_data($filename);
    // Flag that an Meta segment has not been found yet
    $Meta_Location = -1;
    //Cycle through the header segments
    for ($i = 0; $i < count($jpeg_header_data); $i++) {
        // If we find an APP3 header,
        if (strcmp($jpeg_header_data[$i]['SegName'], "APP3") == 0) {
            // And if it has the Meta label,
            if (strncmp($jpeg_header_data[$i]['SegData'], "Meta", 6) == 0 || strncmp($jpeg_header_data[$i]['SegData'], "META", 6) == 0) {
                // Save the location of the Meta segment
                $Meta_Location = $i;
            }
        }
    }
    // Check if an EXIF segment was found
    if ($Meta_Location == -1) {
        // Couldn't find any Meta block to decode
        return FALSE;
    }
    $filehnd = @fopen($filename, 'rb');
    // Check if the file opened successfully
    if (!$filehnd) {
        // Could't open the file - exit
        echo "<p>Could not open file {$filename}</p>\n";
        return FALSE;
    }
    fseek($filehnd, $jpeg_header_data[$Meta_Location]['SegDataStart'] + 6);
    // Decode the Meta segment into an array and return it
    $meta = process_TIFF_Header($filehnd, "Meta");
    // Close File
    fclose($filehnd);
    return $meta;
}
Exemple #8
0
 static function setJpegComment($fname, $comment)
 {
     require_once 'jpeg-toolkit/JPEG.php';
     $headers = get_jpeg_header_data($fname);
     $headers = put_jpeg_Comment($headers, $comment);
     put_jpeg_header_data($fname, $fname, $headers);
 }
 /**
  * get parameters for createRecord
  * 
  * @param mixed input
  * @return array or false on fatal error
  * @access public
  * @since 7/20/05
  */
 function getSingleAssetRecordList($input)
 {
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Harmoni");
         $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
         $priorityType = new Type("logging", "edu.middlebury", "Error", "Events involving critical system errors.");
     }
     $idManager = Services::getService("Id");
     $this->_fileStructureId = $idManager->getId("FILE");
     $fileparts = array("File Name", "Thumbnail Data");
     $this->_fileNamePartIds = $this->matchPartStructures($this->_destinationRepository->getRecordStructure($this->_fileStructureId), $fileparts);
     if (!isset($this->_structureId)) {
         $import = new DOMIT_Document();
         if (!isset($this->_schemaPath)) {
             $this->_schemaPath = $this->getSchemaPath($this->_srcDir);
             if (!$this->_schemaPath) {
                 $this->_schemaPath = DEFAULT_EXIF_SCHEMA;
             }
         }
         if ($import->loadXML($this->_schemaPath)) {
             if (!$import->documentElement->hasChildNodes()) {
                 $this->addError("There are no schemas defined in : " . $this->_schemaPath);
                 if (isset($log)) {
                     $item = new AgentNodeEntryItem("ExifImporter Error", "There are no schemas defined in: " . $this->_schemaPath);
                     $log->appendLogWithTypes($item, $formatType, $priorityType);
                 }
                 return false;
             }
         } else {
             $this->addError("XML parse failed: " . $this->_schemaPath . " does not exist or contains poorly formed XML.");
             if (isset($log)) {
                 $item = new AgentNodeEntryItem("ExifImporter DOMIT Error", "XML parse failed: " . $this->_schemaPath . " does not exist or contains poorly formed XML.");
                 $log->appendLogWithTypes($item, $formatType, $priorityType);
             }
             return false;
         }
         $istructuresList = $import->documentElement->childNodes;
         $this->_structureId = array();
         $this->_partsFinal = array();
         $this->_valuesFinal = array();
         foreach ($istructuresList as $istructure) {
             $valuesPreFinal = array();
             $partStructuresArray = array();
             if ($istructure->nodeName == "recordStructure") {
                 //match the structure
                 $ipartStructures = $istructure->childNodes;
                 if ($ipartStructures[0]->getText() != "") {
                     $matchedSchema = $idManager->getId($ipartStructures[0]->getText());
                 } else {
                     $matchedSchema = $this->matchSchema($ipartStructures[1]->getText(), $this->_destinationRepository);
                 }
                 if ($matchedSchema == false) {
                     $this->addError("Schema: " . $ipartStructures[1]->getText() . " does not exist");
                     if (isset($log)) {
                         $item = new AgentNodeEntryItem("ExifImporter \n\t\t\t\t\t\t\t\tError", "Schema: " . $ipartStructures[1]->getText() . " does not exist.");
                         $log->appendLogWithTypes($item, $formatType, $priorityType);
                     }
                     return false;
                 } else {
                     $this->_structureId[] = $matchedSchema;
                 }
                 //match the partstructures
                 foreach ($ipartStructures as $ipartStructure) {
                     if ($ipartStructure->nodeName == "partStructure") {
                         $ivaluesArray = $ipartStructure->childNodes;
                         if ($ivaluesArray[0]->getText() != "") {
                             $matchedId = $idManager->getId($ivaluesArray[0]->getText());
                         } else {
                             $matchedId = $this->getPartIdByName($ivaluesArray[1]->getText(), $matchedSchema);
                         }
                         if ($matchedId == false) {
                             $this->addError("Part " . $ivaluesArray[1]->getText() . " does not exist.");
                             if (isset($log)) {
                                 $item = new AgentNodeEntryItem("ExifImporter Error", "Part " . $ivaluesArray[1] . " does not exist.");
                                 $log->appendLogWithTypes($item, $formatType, $priorityType);
                             }
                             return false;
                         }
                         $partStructuresArray[] = $matchedId;
                         $repeatableValueArray = array();
                         foreach ($ivaluesArray as $ivalueField) {
                             if ($ivalueField->nodeName == "value") {
                                 $valueArray = array();
                                 $ivaluesChildren = $ivalueField->childNodes;
                                 foreach ($ivaluesChildren as $ivalue) {
                                     if ($ivalue->nodeName == "exifElement") {
                                         $valueArray[] = "exif::" . $ivalue->getText();
                                     }
                                     if ($ivalue->nodeName == "text") {
                                         $valueArray[] = "text::" . $ivalue->getText();
                                     }
                                 }
                                 $repeatableValueArray[] = $valueArray;
                             }
                         }
                         $valuesPreFinal[$matchedId->getIdString()] = $repeatableValueArray;
                     }
                     $this->_valuesFinal[$matchedSchema->getIdString()] = $valuesPreFinal;
                 }
                 $this->_partsFinal[$matchedSchema->getIdString()] = $partStructuresArray;
             }
         }
     }
     $recordList = array();
     $recordListElement = array();
     $headerData = get_jpeg_header_data($input);
     $fileMetaData1 = $this->extractPhotoshopMetaData();
     $fileMetaData2 = $this->extractExifMetaData($input);
     $fileMetaData = array_merge($fileMetaData1, $fileMetaData2);
     $recordListElement['structureId'] = $this->_fileStructureId;
     $recordListElement['partStructureIds'] = $this->_fileNamePartIds;
     $recordListElement['parts'] = array($input, "");
     $recordList[] = $recordListElement;
     $recordListElement = array();
     foreach ($this->_structureId as $structureId) {
         $parts = array();
         $recordListElement['structureId'] = $structureId;
         $recordListElement['partStructureIds'] = $this->_partsFinal[$structureId->getIdString()];
         $partValuesArray = $this->_valuesFinal[$structureId->getIdString()];
         foreach ($partValuesArray as $key => $repeatablePartsArray) {
             $partValues = array();
             foreach ($repeatablePartsArray as $partsComponentsArray) {
                 // If we have a single entry in the value field, create
                 // multiple part values for any repeated source values.
                 if (count($partsComponentsArray) == 1) {
                     $checkExifField = explode("::", $partsComponentsArray[0]);
                     // An Exif Value
                     if ($checkExifField[0] == "exif") {
                         if (isset($fileMetaData[$checkExifField[1]])) {
                             //multi-valued source values
                             if (is_array($fileMetaData[$checkExifField[1]])) {
                                 foreach ($fileMetaData[$checkExifField[1]] as $sourceValue) {
                                     $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $sourceValue);
                                 }
                             } else {
                                 $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $fileMetaData[$checkExifField[1]]);
                             }
                         }
                     } else {
                         $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $checkExifField[1]);
                     }
                 } else {
                     $data = "";
                     foreach ($partsComponentsArray as $partComponent) {
                         $checkExifField = explode("::", $partComponent);
                         // An Exif Value
                         if ($checkExifField[0] == "exif") {
                             if (isset($fileMetaData[$checkExifField[1]])) {
                                 if (is_array($fileMetaData[$checkExifField[1]])) {
                                     $data .= implode(", ", $fileMetaData[$checkExifField[1]]);
                                 } else {
                                     $data .= $fileMetaData[$checkExifField[1]];
                                 }
                             }
                         } else {
                             $data .= $checkExifField[1];
                         }
                     }
                     $partValues[] = $this->getPartObject($structureId, $idManager->getId($key), $data);
                 }
             }
             $parts[] = $partValues;
         }
         $recordListElement['parts'] = $parts;
         $recordList[] = $recordListElement;
     }
     // 		printpre($recordList);
     // 		exit;
     return $recordList;
 }
Exemple #10
0
if (!$couleur) {
    $couleur = $this->GetParameter('pointcolor');
}
// Taille point par défaut : 10
$point_size = $this->GetParameter('pointsize');
if (!$point_size) {
    $point_size = 10;
}
// parametre centrage point
$centrage = $this->GetParameter('pointcenter');
if ($centrage == '') {
    $centrage = 1;
}
// Fin lecture Parametre de l'action
// Lecture commentaires embarqués dans la page
$comment_jpeg = get_jpeg_Comment(get_jpeg_header_data('tools/cartowiki/images/' . $src_map));
// Solution facile de lecture, mais difficile à maintenir : notamment la notation
parse_str($comment_jpeg);
// Fuseau 31T :
// Rappel : Pixel : O,0 en haut gauche
// X Coin inferieur gauche en Pixel
//$Px_echelle_X1['31T']=0;
$Px_echelle_X1['31T'] = $X131T;
// Y Coin inferieur gauche en Pixel
//$Px_echelle_Y1['31T']=539;
$Px_echelle_Y1['31T'] = $Y131T;
// Pour calcul Resolution
// X Coin inferieur droit en Pixel
//$Px_echelle_X2['31T']=805;
$Px_echelle_X2['31T'] = $X231T;
// Y Coin inferieur droit en Pixel
Exemple #11
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();
 }
function get_Meta_JPEG($filename)
{
    // get the JPEG headers
    $jpeg_header_data = get_jpeg_header_data($filename);
    // Flag that an Meta segment has not been found yet
    $Meta_Location = -1;
    //Cycle through the header segments
    for ($i = 0; $i < count($jpeg_header_data); $i++) {
        // If we find an APP3 header,
        if (strcmp($jpeg_header_data[$i]['SegName'], "APP3") == 0) {
            // And if it has the Meta label,
            if (strncmp($jpeg_header_data[$i]['SegData'], "Meta", 6) == 0 || strncmp($jpeg_header_data[$i]['SegData'], "META", 6) == 0) {
                // Save the location of the Meta segment
                $Meta_Location = $i;
            }
        }
    }
    // Check if an EXIF segment was found
    if ($Meta_Location == -1) {
        // Couldn't find any Meta block to decode
        return FALSE;
    }
    $filehnd = @fopen($filename, 'rb');
    // Check if the file opened successfully
    if (!$filehnd) {
        // Could't open the file - exit
        echo "<p>Could not open file {$filename}</p>\n";
        return FALSE;
    }
    fseek($filehnd, $jpeg_header_data[$Meta_Location]['SegDataStart'] + 6);
    // Decode the Meta segment into an array and return it
    $meta = process_TIFF_Header($filehnd, "Meta");
    // Close File
    fclose($filehnd);
    return $meta;
}