save() public method

public save ( $file = null, $quality = 100 )
示例#1
0
 public function ImageThumbCreate($ImageUrl, $ThumbUrl)
 {
     $ImageThumb = new EasyImage($ImageUrl);
     $ImageThumb->resize(346, 230);
     $ImageThumb->crop(320, 180);
     $ImageThumb->save($ThumbUrl);
 }
示例#2
0
 /**
  * Create an image thumb using easyImage extension
  * Requires easyImage Yii extension.
  * @link http://www.yiiframework.com/extension/easyimage/
  * @param string $original_path
  * @param string $new_path
  * @param integer $width
  * @param integer $height
  */
 public static function createEasyImageThumb($original_path, $new_path, $width = 256, $height = 256)
 {
     $image = new EasyImage($original_path);
     $image->resize($width, $height);
     $image->save($new_path);
     if ($original_path !== $new_path) {
         @unlink($original_path);
     }
 }
 public static function createThumb($param)
 {
     if ($param['image'] != '') {
         $root = $_SERVER['DOCUMENT_ROOT'];
         $onlyImgLink = urldecode(str_replace($param['imageDir'], '', $param['image']));
         $img = $root . '/' . $param['imageDir'] . $onlyImgLink;
         if (file_exists($img)) {
             // replace space pada gambar
             $thumbName = self::cleanImgName($onlyImgLink);
             $thumbDir = dirname($root . $param['thumbDir'] . $onlyImgLink);
             // get direktori image basename
             $thumbDir = self::cleanDirName($thumbDir);
             if (!is_dir($thumbDir)) {
                 // create directory thumb image
                 mkdir($thumbDir, 0755, true);
             }
             //create small thumb
             if (isset($param['small'])) {
                 $image = new EasyImage($img);
                 $image->resize(100, 100, EasyImage::RESIZE_HEIGHT);
                 $image->crop(100, 100, 0, 0);
                 $image->save($thumbDir . '/small-' . $thumbName);
             }
             // create medium thumb
             if (isset($param['medium'])) {
                 $image = new EasyImage($img);
                 if (!empty($_POST['w'])) {
                     $image->crop($_POST['w'], $_POST['h'], $_POST['x1'], $_POST['y1']);
                 } else {
                     $image->crop(400, 200, 0, 0);
                 }
                 $image->resize(400, 200, EasyImage::RESIZE_WIDTH);
                 $image->save($thumbDir . '/medium-' . $thumbName);
             }
             // create medium thumb
             if (isset($param['large'])) {
                 $image = new EasyImage($img);
                 if (!empty($_POST['w'])) {
                     $image->crop($_POST['w'], $_POST['h'], $_POST['x1'], $_POST['y1']);
                 } else {
                     $image->crop(650, 400, 0, 0);
                 }
                 $image->resize(650, 400, EasyImage::RESIZE_WIDTH);
                 $image->save($thumbDir . '/large-' . $thumbName);
             }
         }
     }
 }
示例#4
0
文件: Files.php 项目: renziito/webapp
 public static function generarThumbnails($ruta_destino_file, $urlcarpetathumbnail, $nombrefisicofile, $extensionfile)
 {
     $tamañothumbnail = Constante::TAMANIO_THUMBNAIL;
     foreach ($tamañothumbnail as $tamano) {
         $array_explode = explode("x", $tamano);
         $tamano_redimensionado = $array_explode[1];
         $image = new EasyImage($ruta_destino_file);
         $image->resize(NULL, $tamano_redimensionado, EasyImage::RESIZE_HEIGHT);
         if ($image->save("{$urlcarpetathumbnail}/{$nombrefisicofile}{$tamano}." . $extensionfile)) {
             $retorna = true;
         } else {
             return false;
         }
     }
     return $retorna;
 }
示例#5
0
 public function fetchProxyImage($photoUpload, $weibo_id)
 {
     $imgPath = '/upload/' . date('Ymd') . '/';
     if (!is_dir(ROOT_PATH . $imgPath)) {
         mkdir(ROOT_PATH . $imgPath, 0777, TRUE);
     }
     $imageString = file_get_contents($photoUpload);
     $filename = $imgPath . $weibo_id . '.jpg';
     $save = file_put_contents(ROOT_PATH . $filename, $imageString);
     if ($save) {
         $thumb = new EasyImage(ROOT_PATH . $filename);
         $size = getimagesize(ROOT_PATH . $filename);
         $w = 190;
         $h = 190;
         $s_w = $size[0];
         $s_h = $size[1];
         $r1 = $w / $s_w;
         $r2 = $h / $s_h;
         $widthSamller = TRUE;
         if ($r1 > $r2) {
             $r = $r1;
         } else {
             $widthSamller = FALSE;
             $r = $r2;
         }
         $t_w = $r * $s_w;
         $t_h = $r * $s_h;
         // 先等比例 resize
         $thumb->resize($t_w, $t_h);
         // 再裁剪
         // 裁剪 多余的宽
         if (!$widthSamller) {
             $start_x = ($t_w - $w) / 2;
             $start_y = 0;
             $thumb->crop($w, $h, $start_x, $start_y);
         } else {
             $start_x = 0;
             $start_y = $t_h - $h;
             $thumb->crop($w, $h, $start_x, $start_y);
         }
         $thumb->save(ROOT_PATH . $imgPath . $weibo_id . '_thumb.jpg');
         return $filename;
     } else {
         return false;
     }
 }
 /**
  * Add Watermark to existing image
  * @param string $imagePath
  * @param string $watermarkPath
  * @param integer $offsetX
  * @param integer $offsetY
  * @param integer $opacity
  * @return boolean true if image success add watermark false otherwise
  */
 public static function watermark($imagePath, $watermarkPath, $offsetX = null, $offsetY = null, $opacity = 100)
 {
     $status = false;
     if (file_exists($imagePath) && file_exists($watermarkPath)) {
         $watermark = new EasyImage($watermarkPath);
         $image = new EasyImage($imagePath);
         $image->watermark($watermark, $offsetX, $offsetY, $opacity);
         $status = $image->save();
     }
     return $status;
 }
 /**
  * Создает изображения для  загруженых дополнительных изображений (мультизагрузка) в каталоге товаров(элементы)
  * @param null $id_element_model
  * @param string $driver
  * @return bool
  */
 public function chgImgagesCatalogModel($id_element_model = null, $driver = 'GD')
 {
     $filepatch = '../uploads/filestorage/catalog/elements/';
     $model = SiteModuleSettings::model()->find('site_module_id = 4');
     set_time_limit(0);
     $param = array();
     $param['small'] = array('coords' => $model->e_cover_small, 'crop' => $model->e_cover_small_crop, 'color' => $model->e_small_color);
     $param['medium'] = array('coords' => $model->e_cover_medium, 'crop' => $model->e_cover_medium_crop, 'color' => $model->e_medium_color);
     $param['large'] = array('coords' => $model->e_cover_large, 'crop' => $model->e_cover_large_crop, 'color' => $model->e_large_color);
     $param['admin'] = array('coords' => '100x100', 'crop' => 'Resize', 'color' => 'ffffff');
     foreach (CatalogElementsImages::model()->findAll(!empty($id_element_model) ? 'elements_id = ' . $id_element_model : '') as $dataModel) {
         foreach ($param as $name => $data) {
             if (!file_exists($filepatch . $dataModel->image_name . '.' . $dataModel->image)) {
                 continue;
             }
             $image = new EasyImage($filepatch . $dataModel->image_name . '.' . $dataModel->image, $driver);
             //$image = new EasyImage($fileOrigin, 'Imagick');  - для Imagic
             //Накладываем возяной знак
             $watermark = YiiBase::getPathOfAlias('webroot') . '/../uploads/filestorage/catalog/watermark.png';
             if ($model->watermark_type == 1 && file_exists($watermark) && $name != 'admin') {
                 $opacity = 20;
                 $watermark_pos = $model->watermark_pos;
                 //Получаем размеры водяного знака
                 $mark = new EasyImage($watermark);
                 //Позиции водной марки
                 $sizeWm = getimagesize($watermark);
                 $size = getimagesize($filepatch . $dataModel->image_name . '.' . $dataModel->image);
                 switch ($watermark_pos) {
                     case 1:
                         //Замостить
                         for ($y_i = 0; $y_i < $size[1]; $y_i = $y_i + $sizeWm[1]) {
                             for ($x_i = 0; $x_i < $size[0]; $x_i = $x_i + $sizeWm[0]) {
                                 $image->watermark($mark, $x_i, $y_i, $opacity);
                             }
                         }
                         break;
                     case 2:
                         //Изображение в нижнем левом углу
                         $x_i = 0;
                         $y_i = $size[1] - $sizeWm[1];
                         $image->watermark($mark, $x_i, $y_i, $opacity);
                         break;
                     case 3:
                         //Изображение внизу по центру
                         $x_i = $size[0] / 2 - $sizeWm[0] / 2;
                         $y_i = $size[1] - $sizeWm[1];
                         $image->watermark($mark, $x_i, $y_i, $opacity);
                         break;
                     case 4:
                         //Изображение в центре
                         //$x_i =($x/2)-($sizeWm[0]/2);
                         $x_i = $size[0] / 2 - $sizeWm[0] / 2;
                         $y_i = $size[1] / 2 - $sizeWm[1] / 2;
                         $image->watermark($mark, $x_i, $y_i, $opacity);
                         break;
                     case 5:
                         //Изображение в левом верхнем углу
                         $image->watermark($mark, 0, 0, $opacity);
                         break;
                     case 6:
                         //Изображение в нижнем правом углу
                         $x_i = $size[0] - $sizeWm[0];
                         $y_i = $size[1] - $sizeWm[1];
                         $image->watermark($mark, $x_i, $y_i, $opacity);
                         break;
                     default:
                         $image->watermark($mark, 0, 0, $opacity);
                 }
             }
             $coords = explode("x", strtolower($data['coords']));
             $x = $coords[0];
             $y = $coords[1];
             switch ($data['crop']) {
                 case 'Resize':
                     $image->resize($x, $y, EasyImage::RESIZE_AUTO);
                     break;
                 case 'horResize':
                     $image->resize($x, $y, EasyImage::RESIZE_WIDTH);
                     break;
                 case 'verResize':
                     $image->resize($x, $y, EasyImage::RESIZE_HEIGHT);
                     break;
                 case 'insertResize':
                     $image->resize($x, $y, EasyImage::RESIZE_AUTO);
                     $image->background('#' . str_replace("#", "", $data['color']), 100);
                     break;
                 case 'exactResize':
                     $image->crop($x, $y);
                     break;
                 default:
                     $image->resize($x, $y, EasyImage::RESIZE_AUTO);
             }
             //$filepatch.$dataModel->image_name.'.'.$dataModel->image
             $image->save($filepatch . $name . '-' . $dataModel->image_name . '.' . $dataModel->image);
         }
     }
     return true;
 }