示例#1
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);
 }
示例#2
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);
     }
 }