Пример #1
0
 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
 /**
  * Saves the main image to the type, doing transformation work if configured to do so.
  *
  * @return boolean Indicating success.
  */
 function _save_main_image()
 {
     $this->_current_tmpname = $this->_filter->create_tmp_copy($this->_original_tmpname);
     if (!$this->_filter->set_file($this->_current_tmpname)) {
         return false;
     }
     if (isset($this->_identifier)) {
         // we come from the image*s* type
         $blob_identifier = "{$this->_identifier}main";
         $title = $this->_title;
     } else {
         $blob_identifier = 'main';
         $title = $this->title;
     }
     $result = true;
     // Filter if necessary.
     if ($this->filter_chain && !$this->_filter->process_chain($this->filter_chain)) {
         $result = false;
     }
     if ($result) {
         if (array_key_exists('main', $this->_pending_attachments)) {
             unset($this->_pending_attachments['main']);
             $result = $this->update_attachment($blob_identifier, $this->_filename, $title, $this->_target_mimetype, $this->_current_tmpname, false);
         } else {
             $this->delete_attachment($blob_identifier);
             if (isset($this->_attachment_map)) {
                 $this->_attachment_map[$blob_identifier] = array($this->_identifier, 'main');
             }
             $result = $this->add_attachment($blob_identifier, $this->_filename, $title, $this->_target_mimetype, $this->_current_tmpname, false);
         }
     }
     @unlink($this->_current_tmpname);
     return $result;
 }