Ejemplo n.º 1
1
 /**
  * Define Resize
  *
  * @param int     $width
  * @param int     $height
  * @param boolean $force
  *
  * @return Imagine
  */
 public function resize($width, $height, $force = false)
 {
     $width = intval($width);
     $height = intval($height);
     $callback = function () {
     };
     if ($width > 0 || $height > 0) {
         // AutoScale - aspectRatio
         if (!$force) {
             $callback = function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
             };
         }
         $width = $width ?: null;
         $height = $height ?: null;
         $this->image->resize($width, $height, $callback);
     }
     return $this;
 }
Ejemplo n.º 2
1
 public function process()
 {
     $data = $this->loadData();
     if ($data !== true) {
         return $this->failure($data);
     }
     $mobile = (int) $this->getProperty('mobile', 0);
     if ($mobile == 1) {
         $orientation = $this->img->exif('Orientation');
         switch ($orientation) {
             case 3:
                 $this->img->rotate(180);
                 break;
             case 6:
                 $this->img->rotate(-90);
                 break;
             case 8:
                 $this->img->rotate(90);
                 break;
         }
     }
     if (isset($this->data['rotate'])) {
         $rotate = $this->data['rotate'] * -1.0;
         $this->img->rotate($rotate);
     }
     $crop = $this->getProperty('crop', 0);
     if ($crop == 1 && isset($this->data['width']) && isset($this->data['height'])) {
         $width = intval($this->data['width']);
         $height = intval($this->data['height']);
         if ($height != 0 && $width != 0) {
             $this->img->crop($width, $height, intval($this->data['x']), intval($this->data['y']));
         }
     }
     $fileName = $this->generateUniqueFileName();
     $width = (int) $this->md->getOption('resizer.width', null, 0);
     $width = empty($width) ? null : $width;
     $height = (int) $this->md->getOption('resizer.height', null, 0);
     $height = empty($height) ? null : $height;
     $profileName = $this->getProperty('profile', '');
     if (!empty($profileName) && $crop == 1) {
         $profiles = $this->modx->fromJSON($this->md->getOption('cropper.profiles', null, '[]'));
         foreach ($profiles as $profile) {
             if (!isset($profile['name']) || $profile['name'] != $profileName) {
                 continue;
             }
             $profileWidth = (int) $profile['width'];
             $profileHeight = (int) $profile['height'];
             $width = empty($profileWidth) ? $width : $profileWidth;
             $height = empty($profileHeight) ? $height : $profileHeight;
             break;
         }
     }
     if ($width != null || $height != null) {
         $this->img->resize($width, $height, function ($constraint) {
             /** @var \Intervention\Image\Constraint $constraint */
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     }
     $this->img->save($this->uploadPath . $fileName . '.' . $this->extension);
     return $this->success('', array('path' => $this->uploadURL . $fileName . '.' . $this->extension, 'name' => $this->originalName));
 }
Ejemplo n.º 3
0
 public function resizeImage($size)
 {
     $this->image->resize($size, null, function ($constraint) {
         $constraint->aspectRatio();
     });
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * @return string
  */
 public function getAveragePixelColor()
 {
     $this->intervention->resize(1, 1);
     $color = substr($this->intervention->pickColor(0, 0, 'hex'), 1);
     $this->intervention->reset();
     return $color;
 }
Ejemplo n.º 5
0
 /**
  * Resize the image.
  *
  * @param integer $width
  * @param integer $height
  * @param bool $aspectRatio
  * @return $this
  */
 public function resizeImage($width, $height, $aspectRatio = true)
 {
     $this->image->resize($width, $height, function ($constraint) use($aspectRatio) {
         if ($aspectRatio) {
             $constraint->aspectRatio();
         }
         $constraint->upsize();
     });
     return $this;
 }
Ejemplo n.º 6
0
 public function applyFilter(Image $image)
 {
     return $image->resize(420, 420, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     });
 }
Ejemplo n.º 7
0
 public function applyFilter(Image $image)
 {
     return $image->resize(150, 100, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     })->encode('jpg', 75);
 }
Ejemplo n.º 8
0
 /**
  * @param \Intervention\Image\Image $image
  */
 public function run(Image $image)
 {
     $callback = function (Constraint $constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     };
     $image->resize($this->maxWidth, $this->maxHeight, $callback)->interlace($this->interlace);
 }
Ejemplo n.º 9
0
 public function applyFilter(Image $image)
 {
     // resize the image to a height of 1080 and constrain aspect ratio (auto width)
     // prevent possible upsizing
     return $image->resize(1440, null, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     })->blur(12);
 }
Ejemplo n.º 10
0
 /**
  * Upload file to storage.
  *
  * @return void
  */
 public function upload(Image $image)
 {
     $filename = str_pad($this->id, 5, '0', STR_PAD_LEFT) . '.jpg';
     $path = storage_path('app') . "/tmp/";
     $image->resize(320, 200)->encode('jpg', '85')->save($path . $filename);
     $this->storage->move("tmp/" . $filename, config('params.screenshots_path') . "/" . $filename);
     $this->filename = $filename;
     $this->save();
 }
Ejemplo n.º 11
0
 /**
  * Transform the image
  *
  * @param Image $image
  * @return Image
  */
 public function transform(Image $image)
 {
     if ($this->width and $this->height) {
         $image->grab($this->width, $this->height);
     } elseif ($this->width or $this->height) {
         $image->resize($this->width, $this->height, true, false);
     }
     return $image;
 }
Ejemplo n.º 12
0
 public function apply(Image $image)
 {
     $iHeight = $image->height();
     $iWidth = $image->width();
     if ($iHeight == $height && $iWidth == $width) {
         return $image;
     }
     $iRatio = $iWidth / $iHeight;
     $Ratio = $width / $height;
     if ($iRatio > $Ratio) {
         $image->resize($width, null, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     } else {
         $image->resize(null, $height, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
     }
     return $image;
 }
Ejemplo n.º 13
0
 protected function fit()
 {
     if ($this->width !== null || $this->height !== null) {
         if ($this->fit === self::FIT_CROP && $this->width && $this->height) {
             $this->image->fit($this->width, $this->height, function ($constraint) {
                 /* @var $constraint \Intervention\Image\Constraint */
                 $constraint->aspectRatio();
             });
             return;
         }
         if ($this->fit === self::FIT_MIN || $this->fit === self::FIT_MAX) {
             if ($this->fit === self::FIT_MAX) {
                 $this->image->resize($this->width, $this->height, function ($constraint) {
                     /* @var $constraint \Intervention\Image\Constraint */
                     $constraint->aspectRatio();
                     $constraint->upsize();
                 });
                 $this->image->resizeCanvas($this->width, $this->height, 'top-left');
             }
             if ($this->fit === self::FIT_MIN) {
                 $height = $this->image->getHeight() < $this->height ? $this->image->getHeight() : $this->height;
                 $width = $this->image->getWidth() < $this->width ? $this->image->getWidth() : $this->width;
                 $this->image->fit($width, $height, function ($constraint) {
                     /* @var $constraint \Intervention\Image\Constraint */
                     $constraint->aspectRatio();
                     $constraint->upsize();
                 });
             }
             return;
         }
         if ($this->fit === self::FIT_CLIP) {
             $this->image->resize($this->width, $this->height, function ($constraint) {
                 /* @var $constraint \Intervention\Image\Constraint */
                 $constraint->aspectRatio();
                 $constraint->upsize();
             });
             return;
         }
         if ($this->fit === self::FIT_SCALE) {
             $this->image->resize($this->width, $this->height);
             return;
         }
         if ($this->fit === self::FIT_CLAMP) {
             $this->image->resize($this->width, $this->height, function ($constraint) {
                 /* @var $constraint \Intervention\Image\Constraint */
                 $constraint->aspectRatio();
             });
         }
     }
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function createVariation(ImageFormat $output_format, $quality, ImageDimensions $dimensions = null, ImageCropDimensions $crop_dimensions = null)
 {
     try {
         $img = new InterventionImage($this->data);
     } catch (\Intervention\Image\Exception\InvalidImageDataStringException $e) {
         throw new BadImageException('Bad image data', 0, $e);
     } catch (\Intervention\Image\Exception\ImageNotFoundException $e) {
         throw new BadImageException('Not an image', 0, $e);
     }
     if ($dimensions) {
         if ($dimensions->getGrab()) {
             $img->grab($dimensions->getWidth(), $dimensions->getHeight());
         } else {
             $img->resize($dimensions->getWidth(), $dimensions->getHeight(), $dimensions->getMaintainRatio(), $dimensions->canUpscale());
         }
     }
     return $img->encode($output_format->key(), $quality);
 }
Ejemplo n.º 15
0
 /**
  * Get downscaled image if size is higher than limit,
  * return original image if lower.
  *
  * @param  Image  $processImage
  * @return Image
  */
 protected function getDownscaledImage(Image $processImage)
 {
     // prevent possible upsizing
     $processImage->resize($this->maxPixelSize, $this->maxPixelSize, function (Constraint $constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     });
     return $processImage;
 }
Ejemplo n.º 16
0
 public function testBackup()
 {
     $img = new Image(null, 800, 600, '#0000ff');
     $img->fill('#00ff00');
     $img->backup();
     $img->resize(200, 200);
     $img->reset();
     $this->assertInternalType('int', $img->width);
     $this->assertInternalType('int', $img->height);
     $this->assertEquals($img->width, 800);
     $this->assertEquals($img->height, 600);
     $this->assertEquals('#00ff00', $img->pickColor(0, 0, 'hex'));
     $img = new Image('public/tile.png');
     $img->resize(10, 10);
     $img->fill('#00ff00');
     $img->backup();
     $img->resize(5, 5);
     $img->reset();
     $this->assertInternalType('int', $img->width);
     $this->assertInternalType('int', $img->height);
     $this->assertEquals($img->width, 10);
     $this->assertEquals($img->height, 10);
     $this->assertEquals('#00ff00', $img->pickColor(0, 0, 'hex'));
 }
Ejemplo n.º 17
0
 /**
  * Resize current image based on given width/height
  * 
  * Width and height are optional, the not given parameter is calculated
  * 
  * based on the given. The ratio boolean decides whether the resizing
  * 
  * should keep the image ratio. You can also pass along a boolean to
  * 
  * prevent the image from being upsized.
  *
  * @param integer $width The target width for the image
  * @param integer $height The target height for the image
  * @param boolean $ratio Determines if the image ratio should be preserved
  * @param boolean $upsize Determines whether the image can be upsized
  * @return \Intervention\Image\Image 
  * @static 
  */
 public static function resize($width = null, $height = null, $ratio = false, $upsize = true)
 {
     return \Intervention\Image\Image::resize($width, $height, $ratio, $upsize);
 }
Ejemplo n.º 18
0
 /**
  * Handle the image manipulation request
  * @param  \Intervention\Image\Image $image
  * @param  array                     $options
  * @return \Intervention\Image\Image
  */
 public function handle($image, $options)
 {
     $options = array_merge($this->defaults, $options);
     $callback = isset($options['callback']) ? $options['callback'] : null;
     return $image->resize($options['width'], $options['height'], $callback);
 }
Ejemplo n.º 19
0
 /**
  * Applies filter effects to the given image
  *
  * @param Image\Image $image The image to filter.
  *
  * @return Image\Image The filtered image.
  */
 public function applyFilter(Image\Image $image)
 {
     return $image->resize($this->width, $this->height);
 }
Ejemplo n.º 20
0
 public function missingMethod($args)
 {
     if (count($args) < 3) {
         return parent::missingMethod($args);
     }
     if ($args[0] == 'force') {
         array_shift($args);
     }
     $modelKeyword = $args[0];
     $modelClass = \Devhook::getClassByKey($modelKeyword);
     $id = $args[1];
     $file = $args[2];
     $parts = explode('-', $file);
     if (count($parts) == 3) {
         list($field, $sizeKey, $file) = $parts;
         @(list($imageId, $ext) = explode('.', $file));
     } else {
         $imageId = false;
         @(list($field, $file) = $parts);
         @(list($sizeKey, $ext) = explode('.', $file));
     }
     if (!$field || !$sizeKey || $ext != 'jpg') {
         return parent::missingMethod($args);
     }
     $model = $modelClass::find($id);
     if (!$model || !$model->{$field}) {
         return parent::missingMethod($args);
     }
     // $fileExt = pathinfo($model->$field, PATHINFO_EXTENSION);
     $fields = (array) $model->getFields();
     $modelField = isset($fields[$field]) ? $fields[$field] : false;
     if (!$modelField || empty($modelField->type)) {
         return parent::missingMethod($args);
     }
     $imageTypes = array('image');
     $type = $modelField->type;
     $sizes = (array) $modelField->settings('sizes');
     $imageAdminThumb = Config::get('devhook.imageAdminThumb');
     if (!in_array($type, $imageTypes) || empty($sizes[$sizeKey])) {
         return parent::missingMethod($args);
     }
     $watermark = $modelField->settings('watermark');
     $size = $sizes[$sizeKey];
     $width = $size[0];
     $hegiht = $size[1];
     $crop = isset($size[2]) ? $size[2] : false;
     $quality = isset($size[3]) ? $size[3] : 95;
     if ($imageId) {
         $imageFile = \Image::where('imageable_type', $modelKeyword)->where('imageable_id', $id)->find($imageId);
         if (!$imageFile) {
             return parent::missingMethod($args);
         }
         $imageFile = $imageFile->path;
     } else {
         $imageFile = $model->{$field};
     }
     ini_set('memory_limit', '200M');
     $image = new IMG(public_path($imageFile));
     if ($crop) {
         $image->grab($width, $hegiht);
     } else {
         $image->resize($width, $hegiht, true);
     }
     if ($watermark) {
         if (!$watermark['sizes'] || in_array($sizeKey, $watermark['sizes'])) {
             $image->insert($watermark['image'], $watermark['offset'][0], $watermark['offset'][1], $watermark['position']);
         }
     }
     $tmpFile = public_path($model->{$field}) . '.tmp_' . uniqid();
     $newFile = public_path(Config::get('devhook.imageRoute') . '/' . implode('/', $args));
     $newPath = dirname($newFile);
     if (!File::exists($newPath)) {
         File::makeDirectory($newPath, 0777, true);
     }
     $image->save($newFile, $quality);
     $img = $image->encode($ext, $quality);
     $response = Response::make($img, 200);
     $response->header('Content-Type', 'image/jpeg');
     return $response;
 }
Ejemplo n.º 21
0
 public function resize($w, $h)
 {
     $this->image->resize($w, $h, true);
 }
 public function testResetEmptyImage()
 {
     $img = new Image(null, 800, 600);
     $img->resize(300, 200);
     $img->reset();
     $this->assertInternalType('int', $img->width);
     $this->assertInternalType('int', $img->height);
     $this->assertEquals($img->width, 800);
     $this->assertEquals($img->height, 600);
 }
Ejemplo n.º 23
0
 /**
  * Applies filter to given image
  *
  * @param  Image $image
  * @return Image
  */
 public function applyFilter(Image $image)
 {
     return $image->resize(300, null, function ($constraint) {
         $constraint->aspectRatio();
     })->encode('jpg', 40);
 }
Ejemplo n.º 24
0
 public function applyFilter(Image $image)
 {
     return $image->resize(250, 150);
 }
Ejemplo n.º 25
0
 /**
  * Perform stretch resize image manipulation.
  * @param  Image $image The source image.
  * @param  integer $width The width.
  * @param  integer $height The height.
  * @return Image   The manipulated image.
  */
 public function runStretchResize(Image $image, $width, $height)
 {
     return $image->resize($width, $height);
 }
Ejemplo n.º 26
0
 /**
  * Указанная рамка должна помещаться внутрь конечного изображения
  * Т.е. если заказываем 100 на 400 а картинка 2000 на 1000
  * То картинка будет уменьшаться до тех пор пока ее высота меньше указанного
  * или ширина меньше указанного
  *
  * @param \Intervention\Image\Image $img
  * @param                           $w
  * @param                           $h
  *
  * @return \Intervention\Image\Image
  */
 static function resizeBoxInImg(\Intervention\Image\Image $img, $w, $h)
 {
     $ratio_image = $img->width() / $img->height();
     $ratio_box = $w / $h;
     if ($ratio_box < $ratio_image) {
         $_h = $h;
         $_w = null;
     } else {
         $_w = $w;
         $_h = null;
     }
     return $img->resize($_w, $_h, function ($constraint) {
         $constraint->aspectRatio();
     });
 }
Ejemplo n.º 27
0
 public function applyFilter(Image $image)
 {
     return $image->resize(null, 1000, function ($constraint) {
         $constraint->aspectRatio();
     });
 }
Ejemplo n.º 28
0
 public function resizeModeInverse($width, $height)
 {
     $this->image->resize($width, $height, true, false);
 }
Ejemplo n.º 29
0
 /**
  * Resize an image to the given dimensions (ignoring aspect ratio).
  *
  * @param int $width The target width, in pixels.
  * @param int $height The target height, in pixels.
  */
 public function resize($width, $height)
 {
     $this->image->resize($width, $height);
 }
Ejemplo n.º 30
0
 public function runShrink(Image $image, $width, $color)
 {
     return $image->resize($image->width() - $width * 2, $image->height() - $width * 2)->resizeCanvas($width * 2, $width * 2, 'center', true, $color);
 }