Esempio n. 1
0
 protected function admin_preview_path($data)
 {
     //if (!isset($this->value())) return false;
     $value = trim($this->value());
     if ($value == '') {
         return false;
     }
     $dir = $this->cache_dir($name, $data, $item);
     $size = 200;
     if (isset($data['admin_preview_size'])) {
         $size = $data['admin_preview_size'];
     }
     $url = $this->get_preview_url();
     $path = $this->original_preview_path();
     if (!IO_FS::exists($path)) {
         return false;
     }
     $preview_path = "{$dir}/{$this->name}-admin-preview.jpg";
     $create = false;
     if (IO_FS::exists($preview_path)) {
         if (filemtime($path) > filemtime($preview_path)) {
             $create = true;
         }
     } else {
         $create = true;
     }
     if ($create) {
         CMS::mkdirs($dir);
         Core::load('CMS.Images');
         CMS_Images::Image($path)->fit($size, $size)->save($preview_path);
     }
     return $preview_path;
 }
Esempio n. 2
0
 protected function mods_process($path)
 {
     IO_FS::mkdir($path, null, true)->set_permission();
     Core::load('CMS.Images');
     foreach ($this->filelist() as $f) {
         $name = pathinfo($f, PATHINFO_BASENAME);
         if (isset($this->to_remake[$name])) {
             $image = CMS_Images::Image($f);
             $image->modify($this->mods);
             $file = "{$path}/{$name}";
             $image->save("{$path}/{$name}");
             IO_FS::File($file)->set_permission();
         }
     }
     $this->to_remake = array();
 }
Esempio n. 3
0
 public function resize_image($filename, $parms)
 {
     Core::load('CMS.Images');
     list($w, $h) = CMS_Images::size($filename);
     if (!$w || !$h) {
         return;
     }
     $nw = $w;
     $nh = $h;
     if (isset($parms['crop'])) {
         list($rw, $rh) = CMS_Images::string2sizes($parms['crop']);
         $rw = (int) $rw;
         $rh = (int) $rh;
         if ($rw != $w || $rh != $h || isset($parms['grayscale']) || isset($parms['watermark'])) {
             $img = CMS_Images::Image($filename);
             if ($rw != $w || $rh != $h) {
                 $img = $img->crop($rw, $rh);
             }
             $img = $this->wg($img, $parms);
             $img->save($filename);
         }
         return;
     }
     if (isset($parms['margins'])) {
         list($rw, $rh) = CMS_Images::string2sizes($parms['margins']);
         $rw = (int) $rw;
         $rh = (int) $rh;
         $color = '#FFFFFF';
         if (isset($parms['margins_color'])) {
             $color = $parms['margins_color'];
         }
         if ($rw != $w || $rh != $h || isset($parms['grayscale']) || isset($parms['watermark'])) {
             $img = CMS_Images::Image($filename);
             if ($rw != $w || $rh != $h) {
                 $img = $img->fit_with_margins($rw, $rh, $color);
             }
             $img = $this->wg($img, $parms);
             $img->save($filename);
         }
         return;
     }
     $fit = true;
     if (isset($parms['resize'])) {
         list($rw, $rh) = CMS_Images::string2sizes($parms['resize']);
         $rw = (int) $rw;
         $rh = (int) $rh;
         if ($rw > 0) {
             $nw = $rw;
         }
         if ($rh > 0) {
             $nh = $rh;
         }
         $fit = false;
     } else {
         if (isset($parms['fit'])) {
             list($rw, $rh) = CMS_Images::string2sizes($parms['fit']);
             $rw = (int) $rw;
             $rh = (int) $rh;
             if ($rw < $nw) {
                 $nw = $rw;
             }
             if ($rh < $nh) {
                 $nh = $rh;
             }
             $fit = true;
         }
     }
     if ($nw != $w || $nh != $h) {
         $img = CMS_Images::Image($filename)->resize($nw, $nh, $fit);
         $img = $this->wg($img, $parms);
         $img->save($filename);
         return;
     }
     if (isset($parms['grayscale']) || isset($parms['watermark'])) {
         $img = CMS_Images::Image($filename);
         $img = $this->wg($img, $parms);
         $img->save($filename);
     }
 }
Esempio n. 4
0
 public static function upload_resize($name, $data, $new_file)
 {
     $upload_mods = self::value($data, 'upload_mods');
     if (!empty($upload_mods)) {
         $mods = self::parse_mods($upload_mods);
         if (!empty($mods)) {
             Core::load('CMS.Images');
             $im = CMS_Images::Image($new_file);
             self::apply_mods($im, $mods);
             $im->save($new_file);
             IO_FS::File($new_file)->set_permission();
         }
     }
 }