コード例 #1
0
 public static function &get_uploader($prefix = '', $destdir = '')
 {
     $mod = cge_utils::get_cge();
     $obj = new cge_uploader($prefix, $destdir);
     $obj->set_accepted_filetypes($mod->GetPreference('alloweduploadfiles'));
     $obj->set_accepted_imagetypes($mod->GetPreference('imageextensions'));
     $obj->set_preview($mod->GetPreference('allow_resizing', 0));
     $obj->set_preview_size($mod->GetPreference('resizeimage', 0));
     $obj->set_watermark($mod->GetPreference('allow_watermarking', 0));
     $obj->set_thumbnail($mod->GetPreference('allow_thumbnailing', 0));
     $obj->set_thumbnail_size($mod->GetPreference('thumbnailsize'));
     $obj->set_delete_orig($mod->GetPreference('delete_orig_image'));
     return $obj;
 }
コード例 #2
0
 public static function transform_image($srcSpec, $destSpec, $size = '')
 {
     $config = cmsms()->GetConfig();
     require_once $config['root_path'] . '/lib/filemanager/ImageManager/Classes/Transform.php';
     if ($size == '') {
         $cge = cge_utils::get_cge();
         $size = $cge->GetPreference('thumbnailsize');
     }
     $it = new Image_Transform();
     $img = $it->factory($config['image_manipulation_prog']);
     $img->load($srcSpec);
     if ($img->img_x < $img->img_y) {
         $long_axis = $img->img_y;
     } else {
         $long_axis = $img->img_x;
     }
     if ($long_axis > $size) {
         $img->scaleByLength($size);
         $img->save($destSpec, 'jpeg');
     } else {
         $img->save($destSpec, 'jpeg');
     }
     $img->free();
 }
コード例 #3
0
 /**
  * Resize an image to have the specifified number of pixels in the logest dimension while retaining aspect ratio.
  *
  * @param string $srcSpec The complete path to the input file.
  * @param string $destSpec The complete path to the output file.
  * @param int $size The maximum size of the longest dimension of the image (in pixels).
  */
 public static function transform_image($srcSpec, $destSpec, $size = null)
 {
     if (!file_exists($srcSpec)) {
         throw new \CmsInvalidDataException('File ' . $srcSpec . ' not found');
     }
     if (!is_readable($srcSpec)) {
         throw new \CmsInvalidDataException('File ' . $srcSpec . ' is not readable');
     }
     $destdir = dirname($destSpec);
     if (!is_writable($destdir)) {
         throw new \CmsInvalidDataException($destdir . ' is not writable');
     }
     if (file_exists($destSpec) && !is_writable($destSpec)) {
         throw new \CmsInvalidDataException($destSpec . ' exists, but cannot be overwritten.');
     }
     $imginfo = getimagesize($srcSpec);
     if ($imginfo === FALSE) {
         throw new \RuntimeException($srcSpec . ' is not a valid image file (could not get dimensions)');
     }
     if ($size < 1) {
         // get a default thumbnail size.
         $cge = cge_utils::get_cge();
         $size = (int) $cge->GetPreference('thumbnailsize');
     }
     // calculate new sizes.
     $new_w = $new_h = 0;
     if ($imginfo[0] >= $imginfo[1]) {
         // image is taller than wide
         $new_w = $size;
         $new_h = round($new_w / $imginfo[0] * $imginfo[1], 0);
     } else {
         $new_h = $size;
         $new_w = round($new_h / $imginfo[1] * $imginfo[0], 0);
     }
     self::resize($srcSpec, $destSpec, $new_w, $new_h);
 }
コード例 #4
0
 /**
  * Geerate tags (such as stylesheet tags) that are required for the HEAD portion of the HTML output.
  *
  * @return string The HTML tags to go into the HEAD portion.
  */
 protected function get_head_contents()
 {
     $out = '';
     if (count($this->_stylesheets)) {
         $mod = \cge_utils::get_cge();
         foreach ($this->_stylesheets as $one) {
             if (!file_exists($one)) {
                 continue;
             }
             $url = \cge_utils::file_to_url($one);
             if (!$url) {
                 continue;
             }
             $out .= '<link rel="stylesheet" type="text/css" href="' . $url . '">';
         }
     }
     return $out;
 }
コード例 #5
0
 /**
  * Preprocess the uploaded image file.  If the file is in the accepted image types.
  * by default this method will generate a preview image (if enabled), and then optionally watermark it.
  *
  * @param array $fileinfo The fileinfo array passed from the $_FILES upload global.
  * @return string The path and filename of the destination file.
  */
 protected function preprocess_upload($fileinfo)
 {
     $srcname = $fileinfo['tmp_name'];
     if (!$this->is_accepted_imagefile($fileinfo['name'])) {
         return $srcname;
     }
     if ($this->_do_preview && $this->_preview_size > 0) {
         // I guess we're resizing the master image.
         $destdir = dirname($srcname);
         $destname = 'rs_' . basename($srcname);
         $tmpname = $destdir . '/' . $destname;
         cge_image::transform_image($srcname, $tmpname, $this->_preview_size);
         if (!file_exists($tmpname)) {
             $mod = cge_utils::get_cge();
             $this->set_error($mod->Lang('error_image_transform'));
             return FALSE;
         } else {
             if ($this->_delete_orig) {
                 @unlink($srcname);
                 @rename($tmpname, $srcname);
             } else {
                 $srcname = $tmpname;
             }
         }
     }
     if ($this->_do_watermark) {
         // I guess we're creating a watermark image.
         $destdir = dirname($srcname);
         $destname = 'wm_' . basename($srcname);
         $tmpname = $destdir . '/' . $destname;
         $obj = $this->get_watermark_obj();
         try {
             $res = $obj->create_watermarked_image($srcname, $tmpname);
             @unlink($srcname);
             $srcname = $tmpname;
         } catch (\Exception $e) {
             $this->set_error('WATERMARKING: ' . $e->GetMessage());
         }
     }
     return $srcname;
 }