Ejemplo n.º 1
0
 private function _gmagickRead($ps_filepath)
 {
     try {
         $handle = new Gmagick($ps_filepath);
         $this->setResourceLimits($handle);
         $handle->setimageindex(0);
         // force use of first image in multi-page TIFF
         $this->handle = $handle;
         $this->filepath = $ps_filepath;
         $this->metadata = array();
         // handle metadata
         /* EXIF */
         if (function_exists('exif_read_data') && !$this->opo_config->get('dont_use_exif_read_data')) {
             if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
                 $va_metadata['EXIF'] = $va_exif;
             }
         }
         // if the builtin EXIF extraction is not used or failed for some reason, try ExifTool
         if (!isset($va_metadata['EXIF']) || !is_array($va_metadata['EXIF'])) {
             if (caExifToolInstalled()) {
                 $va_metadata['EXIF'] = caExtractMetadataWithExifTool($ps_filepath, true);
             }
         }
         // Rotate incoming image as needed
         if (isset($va_metadata['EXIF']['IFD0']['Orientation'])) {
             $vn_orientation = $va_metadata['EXIF']['IFD0']['Orientation'];
             $vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
             $vb_is_rotated = false;
             switch ($vn_orientation) {
                 case 3:
                     $this->handle->rotateimage("#FFFFFF", 180);
                     unset($va_metadata['EXIF']['IFD0']['Orientation']);
                     $vb_is_rotated = true;
                     break;
                 case 6:
                     $this->handle->rotateimage("#FFFFFF", 90);
                     unset($va_metadata['EXIF']['IFD0']['Orientation']);
                     $vb_is_rotated = true;
                     break;
                 case 8:
                     $this->handle->rotateimage("#FFFFFF", -90);
                     unset($va_metadata['EXIF']['IFD0']['Orientation']);
                     $vb_is_rotated = true;
                     break;
             }
             if ($vb_is_rotated) {
                 if ($this->handle->writeimage($vs_tmp_basename)) {
                     $va_tmp = $this->handle->getimagegeometry();
                     $this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
                 }
                 @unlink($vs_tmp_basename);
             }
         }
         // get XMP
         $o_xmp = new XMPParser();
         if ($o_xmp->parse($ps_filepath)) {
             if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                 $va_metadata['XMP'] = array();
                 foreach ($va_xmp_metadata as $vs_xmp_tag => $va_xmp_values) {
                     $va_metadata['XMP'][$vs_xmp_tag] = join('; ', $va_xmp_values);
                 }
             }
         }
         // try to get IPTC and DPX with GraphicsMagick, if available
         if (caMediaPluginGraphicsMagickInstalled()) {
             /* IPTC metadata */
             $vs_iptc_file = tempnam(caGetTempDirPath(), 'gmiptc');
             @rename($vs_iptc_file, $vs_iptc_file . '.iptc');
             // GM uses the file extension to figure out what we want
             $vs_iptc_file .= '.iptc';
             exec($this->ops_graphicsmagick_path . " convert " . caEscapeShellArg($ps_filepath) . " " . caEscapeShellArg($vs_iptc_file) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
             $vs_iptc_data = file_get_contents($vs_iptc_file);
             @unlink($vs_iptc_file);
             $va_iptc_raw = iptcparse($vs_iptc_data);
             $va_iptc_tags = array('2#004' => 'Genre', '2#005' => 'DocumentTitle', '2#010' => 'Urgency', '2#015' => 'Category', '2#020' => 'Subcategories', '2#025' => 'Keywords', '2#040' => 'SpecialInstructions', '2#055' => 'CreationDate', '2#060' => 'TimeCreated', '2#080' => 'AuthorByline', '2#085' => 'AuthorTitle', '2#090' => 'City', '2#095' => 'State', '2#100' => 'CountryCode', '2#101' => 'Country', '2#103' => 'OTR', '2#105' => 'Headline', '2#110' => 'Credit', '2#115' => 'PhotoSource', '2#116' => 'Copyright', '2#120' => 'Caption', '2#122' => 'CaptionWriter');
             $va_iptc = array();
             if (is_array($va_iptc_raw)) {
                 foreach ($va_iptc_raw as $vs_iptc_tag => $va_iptc_tag_data) {
                     if (isset($va_iptc_tags[$vs_iptc_tag])) {
                         $va_iptc[$va_iptc_tags[$vs_iptc_tag]] = join('; ', $va_iptc_tag_data);
                     }
                 }
             }
             if (sizeof($va_iptc)) {
                 $va_metadata['IPTC'] = $va_iptc;
             }
             /* DPX metadata */
             exec($this->ops_graphicsmagick_path . " identify -format '%[DPX:*]' " . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
             if ($va_output[0]) {
                 $va_metadata['DPX'] = $va_output;
             }
         }
         $this->metadata = $va_metadata;
         return $handle;
     } catch (Exception $e) {
         $this->postError(1610, _t("Could not read image file"), "WLPlugGmagick->read()");
         return false;
         // gmagick couldn't read file, presumably
     }
 }
Ejemplo n.º 2
0
 private function _CoreImageRead($ps_filepath)
 {
     if (caMediaPluginCoreImageInstalled($this->ops_CoreImage_path)) {
         $vs_output = shell_exec('sips --getProperty format --getProperty space --getProperty bitsPerSample --getProperty pixelWidth --getProperty pixelHeight --getProperty dpiWidth --getProperty dpiHeight ' . caEscapeShellArg($ps_filepath) . " 2> /dev/null");
         $va_tmp = explode("\n", $vs_output);
         array_shift($va_tmp);
         $va_properties = array();
         foreach ($va_tmp as $vs_line) {
             $va_line_tmp = explode(':', $vs_line);
             $va_properties[trim($va_line_tmp[0])] = trim($va_line_tmp[1]);
         }
         //
         // TODO: Rotate incoming image as needed
         //
         $vn_orientation_rotation = null;
         if (function_exists('exif_read_data')) {
             if (is_array($va_exif = @exif_read_data($ps_filepath, 'EXIF', true, false))) {
                 if (isset($va_exif['IFD0']['Orientation'])) {
                     $vn_orientation = $va_exif['IFD0']['Orientation'];
                     switch ($vn_orientation) {
                         case 3:
                             $vn_orientation_rotation = 180;
                             break;
                         case 6:
                             $vn_orientation_rotation = 90;
                             break;
                         case 8:
                             $vn_orientation_rotation = -90;
                             break;
                     }
                 }
             }
         }
         $va_faces = caDetectFaces($ps_filepath, $va_properties['pixelWidth'], $va_properties['pixelHeight']);
         return array('mimetype' => $this->appleTypeToMimeType($va_properties['format']), 'magick' => $va_properties['format'], 'width' => in_array($vn_orientation_rotation, array(90, -90)) ? $va_properties['pixelHeight'] : $va_properties['pixelWidth'], 'height' => in_array($vn_orientation_rotation, array(90, -90)) ? $va_properties['pixelWidth'] : $va_properties['pixelHeight'], 'colorspace' => $va_properties['space'], 'depth' => $va_properties['bitsPerSample'], 'orientation_rotate' => $vn_orientation_rotation, 'resolution' => array('x' => $va_properties['dpiWidth'], 'y' => $va_properties['dpiHeight']), 'ops' => array(), 'faces' => $va_faces, 'filepath' => $ps_filepath);
     }
     return null;
 }
Ejemplo n.º 3
0
 private function _graphicsMagickRead($ps_filepath)
 {
     if (caMediaPluginGraphicsMagickInstalled($this->ops_graphicsmagick_path)) {
         exec($this->ops_graphicsmagick_path . ' identify -format "%m;%w;%h;%q;%x;%y\\n" ' . caEscapeShellArg($ps_filepath) . (caIsPOSIX() ? " 2> /dev/null" : ""), $va_output, $vn_return);
         $va_tmp = explode(';', $va_output[0]);
         if (sizeof($va_tmp) != 6) {
             return null;
         }
         $this->metadata = $this->_graphicsMagickGetMetadata($ps_filepath);
         //
         // Rotate incoming image as needed
         //
         if (isset($this->metadata['EXIF']) && is_array($va_exif = $this->metadata['EXIF'])) {
             if (isset($va_exif['IFD0']['Orientation'])) {
                 $vn_orientation = $va_exif['IFD0']['Orientation'];
                 switch ($vn_orientation) {
                     case 3:
                         $this->properties["orientation_rotate"] = -180;
                         break;
                     case 6:
                         $this->properties["orientation_rotate"] = 90;
                         break;
                     case 8:
                         $this->properties["orientation_rotate"] = -90;
                         break;
                 }
             }
         }
         $va_faces = caDetectFaces($ps_filepath, $va_tmp[1], $va_tmp[2]);
         return array('mimetype' => $this->magickToMimeType($va_tmp[0]), 'magick' => $va_tmp[0], 'width' => in_array($this->properties["orientation_rotate"], array(90, -90)) ? $va_tmp[2] : $va_tmp[1], 'height' => in_array($this->properties["orientation_rotate"], array(90, -90)) ? $va_tmp[1] : $va_tmp[2], 'depth' => $va_tmp[3], 'resolution' => array('x' => $va_tmp[4], 'y' => $va_tmp[5]), 'ops' => $this->properties["orientation_rotate"] ? array(0 => array('op' => 'strip')) : array(), 'faces' => $va_faces, 'filepath' => $ps_filepath);
     }
     return null;
 }
Ejemplo n.º 4
0
 public function read($ps_filepath, $mimetype = "")
 {
     if (!($this->handle && ${$ps_filepath} === $this->filepath)) {
         if ($mimetype == 'image/tilepic') {
             #
             # Read in Tilepic format image
             #
             $this->handle = new TilepicParser($ps_filepath);
             if (!$this->handle->error) {
                 $this->filepath = $ps_filepath;
                 foreach ($this->handle->properties as $k => $v) {
                     if (isset($this->properties[$k])) {
                         $this->properties[$k] = $v;
                     }
                 }
                 $this->properties["mimetype"] = "image/tilepic";
                 $this->properties["typename"] = "Tilepic";
                 return 1;
             } else {
                 $this->postError(1610, $this->handle->error, "WLPlugImagick->read()");
                 return false;
             }
         } else {
             $this->handle = "";
             $this->filepath = "";
             $handle = new Imagick();
             if ($mimetype == 'image/x-dcraw') {
                 if ($this->filepath_conv) {
                     @unlink($this->filepath_conv);
                 }
                 if (!caMediaPluginDcrawInstalled($this->ops_dcraw_path)) {
                     $this->postError(1610, _t("Could not convert Camera RAW format file because conversion tool (dcraw) is not installed"), "WLPlugImagick->read()");
                     return false;
                 }
                 $vs_tmp_name = tempnam(caGetTempDirPath(), "rawtmp");
                 if (!copy($ps_filepath, $vs_tmp_name)) {
                     $this->postError(1610, _t("Could not copy Camera RAW file to temporary directory"), "WLPlugImagick->read()");
                     return false;
                 }
                 exec($this->ops_dcraw_path . " -T " . caEscapeShellArg($vs_tmp_name), $va_output, $vn_return);
                 if ($vn_return != 0) {
                     $this->postError(1610, _t("Camera RAW file conversion failed: %1", $vn_return), "WLPlugImagick->read()");
                     return false;
                 }
                 if (!(file_exists($vs_tmp_name . '.tiff') && filesize($vs_tmp_name . '.tiff') > 0)) {
                     $this->postError(1610, _t("Translation from Camera RAW to TIFF failed"), "WLPlugImagick->read()");
                     return false;
                 }
                 $ps_filepath = $this->filepath_conv = $vs_tmp_name . '.tiff';
                 @unlink($vs_tmp_name);
             }
             if ($handle->readImage($ps_filepath)) {
                 $this->handle = $handle;
                 $this->filepath = $ps_filepath;
                 $va_raw_metadata = $this->handle->getImageProperties();
                 $this->metadata = array();
                 foreach ($va_raw_metadata as $vs_tag => $vs_value) {
                     if (sizeof($va_tmp = explode(':', $vs_tag)) > 1) {
                         $vs_type = strtoupper($va_tmp[0]);
                         $vs_tag = $va_tmp[1];
                     } else {
                         $vs_type = 'GENERIC';
                     }
                     if ($vs_type == 'EXIF') {
                         continue;
                     }
                     $this->metadata[$vs_type][$vs_tag] = $vs_value;
                 }
                 // exif
                 if (function_exists('exif_read_data')) {
                     if (is_array($va_exif = caSanitizeArray(@exif_read_data($ps_filepath, 'EXIF', true, false)))) {
                         //
                         // Rotate incoming image as needed
                         //
                         if (isset($va_exif['IFD0']['Orientation'])) {
                             $vn_orientation = $va_exif['IFD0']['Orientation'];
                             $vs_tmp_basename = tempnam(caGetTempDirPath(), 'ca_image_tmp');
                             $vb_is_rotated = false;
                             switch ($vn_orientation) {
                                 case 3:
                                     $this->handle->rotateImage("#FFFFFF", 180);
                                     unset($va_exif['IFD0']['Orientation']);
                                     $vb_is_rotated = true;
                                     break;
                                 case 6:
                                     $this->handle->rotateImage("#FFFFFF", 90);
                                     unset($va_exif['IFD0']['Orientation']);
                                     $vb_is_rotated = true;
                                     break;
                                 case 8:
                                     $this->handle->rotateImage("#FFFFFF", -90);
                                     unset($va_exif['IFD0']['Orientation']);
                                     $vb_is_rotated = true;
                                     break;
                             }
                             if ($vb_is_rotated) {
                                 if ($this->handle->writeImage($vs_tmp_basename)) {
                                     $va_tmp = $this->handle->getImageGeometry();
                                     $this->properties["faces"] = $this->opa_faces = caDetectFaces($vs_tmp_basename, $va_tmp['width'], $va_tmp['height']);
                                 }
                                 @unlink($vs_tmp_basename);
                             }
                         }
                         $this->metadata['EXIF'] = $va_exif;
                     }
                 }
                 // XMP
                 $o_xmp = new XMPParser();
                 if ($o_xmp->parse($ps_filepath)) {
                     if (is_array($va_xmp_metadata = $o_xmp->getMetadata()) && sizeof($va_xmp_metadata)) {
                         $this->metadata['XMP'] = $va_xmp_metadata;
                     }
                 }
                 # load image properties
                 $va_tmp = $this->handle->getImageGeometry();
                 $this->properties["width"] = $va_tmp['width'];
                 $this->properties["height"] = $va_tmp['height'];
                 $this->properties["quality"] = "";
                 $this->properties["filesize"] = $this->handle->getImageLength();
                 $this->properties["bitdepth"] = $this->handle->getImageDepth();
                 $this->properties["resolution"] = $this->handle->getImageResolution();
                 $this->properties["colorspace"] = $this->_getColorspaceAsString($this->handle->getImageColorspace());
                 // force all images to true color (takes care of GIF transparency for one thing...)
                 $this->handle->setImageType(imagick::IMGTYPE_TRUECOLOR);
                 if (!$this->handle->setImageColorspace(imagick::COLORSPACE_RGB)) {
                     $this->postError(1610, _t("Error during RGB colorspace transformation operation"), "WLPlugImagick->read()");
                     return false;
                 }
                 if (!$this->properties["faces"]) {
                     $this->properties["faces"] = $this->opa_faces = caDetectFaces($ps_filepath, $va_tmp['width'], $va_tmp['height']);
                 }
                 $this->properties["mimetype"] = $this->_getMagickImageMimeType($this->handle);
                 $this->properties["typename"] = $this->handle->getImageFormat();
                 $this->ohandle = $this->handle->clone();
                 return 1;
             } else {
                 $this->postError(1610, _t("Could not read image file"), "WLPlugImagick->read()");
                 return false;
             }
         }
     } else {
         # image already loaded by previous call (probably divineFileFormat())
         return 1;
     }
 }