示例#1
0
文件: image.php 项目: nemein/openpsa
 public function generate_image($type, $filter_chain)
 {
     try {
         $original = new midcom_db_attachment($this->attachment);
     } catch (midcom_error $e) {
         $e->log();
         return false;
     }
     $found_derived = false;
     try {
         $derived = new midcom_db_attachment($this->{$type});
         $found_derived = true;
     } catch (midcom_error $e) {
         $derived = new midcom_db_attachment();
         $derived->parentguid = $original->parentguid;
         $derived->title = $original->title;
         $derived->mimetype = $original->mimetype;
         $derived->name = $type . '_' . $original->name;
     }
     $imagefilter = new midcom_helper_imagefilter($original);
     if (!$imagefilter->process_chain($filter_chain)) {
         throw new midcom_error('Image processing failed');
     }
     if (!$found_derived) {
         if (!$derived->create()) {
             throw new midcom_error('Failed to create derived image: ' . midcom_connection::get_error_string());
         }
         $this->{$type} = $derived->id;
         $this->update();
     }
     return $imagefilter->write($derived);
 }
示例#2
0
文件: video.php 项目: nemein/openpsa
 /**
  * Automatically convert the uploaded file to a web-compatible type. Uses
  * only the first image of multi-page uploads (like PDFs) and populates the
  * _target_mimetype member accordingly. The original_tmpname file is manipulated
  * directly.
  *
  * Uploaded GIF, PNG and JPEG files are left untouched.
  *
  * In case of any conversions being done, the new extension will be appended
  * to the uploaded file.
  *
  * @return boolean Indicating success
  */
 function _auto_convert_to_web_type()
 {
     debug_add("\$this->_original_mimetype: {$this->_original_mimetype}");
     switch ($this->_original_mimetype) {
         case 'image/png':
         case 'image/gif':
         case 'image/jpeg':
             $this->_target_mimetype = $this->_original_mimetype;
             $conversion = null;
             break;
         case 'application/postscript':
         case 'application/pdf':
             $this->_target_mimetype = 'image/png';
             $conversion = 'png';
             break;
         default:
             $this->_target_mimetype = 'image/jpeg';
             $conversion = 'jpg';
             break;
     }
     debug_add("\$conversion={$conversion}");
     if (empty($conversion)) {
         return true;
     }
     if (!midcom_helper_imagefilter::imagemagick_available()) {
         throw new midcom_error('DM2 type image requires ImageMagick for manipulation operations, see debug log for details');
     }
     // PONDER: Make sure there is only one extension on the file ??
     $this->_filename .= ".{$conversion}";
     return $this->_filter->convert($conversion);
 }
示例#3
0
文件: image.php 项目: nemein/openpsa
 /**
  * Automatically convert the uploaded file to a web-compatible type. Uses
  * only the first image of multi-page uploads (like PDFs) and populates the
  * _target_mimetype member accordingly. The original_tmpname file is manipulated
  * directly.
  *
  * Uploaded GIF, PNG and JPEG files are left untouched.
  *
  * In case of any conversions being done, the new extension will be appended
  * to the uploaded file.
  *
  * @return boolean Indicating success
  */
 function _auto_convert_to_web_type()
 {
     debug_add("\$this->_original_mimetype: {$this->_original_mimetype}");
     switch (preg_replace('/;.+$/', '', $this->_original_mimetype)) {
         case 'image/png':
         case 'image/gif':
         case 'image/jpeg':
             debug_add('No conversion necessary we already have a web mime type');
             return true;
         case 'application/postscript':
         case 'application/pdf':
             $this->_target_mimetype = 'image/png';
             $conversion = 'png';
             break;
         default:
             $this->_target_mimetype = 'image/jpeg';
             $conversion = 'jpg';
             break;
     }
     debug_add("\$conversion={$conversion}");
     if (!$this->imagemagick_available()) {
         throw new midcom_error('DM2 type image requires ImageMagick for manipulation operations, see debug log for details');
     }
     // Prevent double .jpg.jpg in case of trouble file the get_mimetype()
     if (!preg_match("/\\.{$conversion}\$/", $this->_filename)) {
         $this->_filename .= ".{$conversion}";
         // Make sure there is only one extension on the file ??
         $this->_filename = midcom_db_attachment::safe_filename($this->_filename, true);
     }
     if ($this->_filter) {
         return $this->_filter->convert($conversion);
     }
 }
示例#4
0
文件: images.php 项目: nemein/openpsa
 /**
  * Recreates all images from either the "original" or the "main" image
  */
 function recreate_images()
 {
     foreach ($this->images as $identifier => $images) {
         $image = null;
         if (isset($images['original'])) {
             $image = $images['original'];
         } else {
             if (isset($images['main'])) {
                 $image = $images['main'];
             }
         }
         if (!$image) {
             debug_add("Image {$identifier} has no 'original' or 'main' image, skipping recreation.", MIDCOM_LOG_INFO);
             continue;
         }
         if (empty($image['object'])) {
             debug_add("Image {$identifier} has no image object, skipping recreation.", MIDCOM_LOG_INFO);
             continue;
         }
         // Copy the "main image" to a temporary location
         $filter = new midcom_helper_imagefilter();
         $tmp = $filter->create_tmp_copy($image['object']);
         // Update all derived images
         if (!$this->update_image($identifier, $image['filename'], $tmp, $this->titles[$identifier])) {
             debug_add("Failed to recreate image {$identifier}, skipping .", MIDCOM_LOG_INFO);
         }
     }
     return true;
 }