Esempio n. 1
0
 private function _dcrawConvertToTiff($ps_filepath)
 {
     if (!caMediaPluginDcrawInstalled($this->ops_dcraw_path)) {
         $this->postError(1610, _t("Could not convert Camera RAW format file because conversion tool (dcraw) is not installed"), "WLPlugGmagick->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"), "WLPlugGmagick->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), "WLPlugGmagick->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"), "WLPlugGmagick->read()");
         return false;
     }
     return $vs_tmp_name . '.tiff';
 }
Esempio n. 2
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;
     }
 }