public function resize($width, $height, $upscale = false) { if ($upscale === false && ($width >= $this->image_class->get_width() || $height >= $this->image_class->get_height())) { return $this; } $this->image_class->resize($width, $height); return $this; }
/** * @return SimpleImage */ protected function create() { $image = new SimpleImage($this->file); switch ($this->options['strategy']) { case 'thumbnail': $width = $this->options['w'] ?: $image->get_width(); $height = $this->options['h'] ?: $image->get_height(); $image->resize($width, $height); break; case 'best_fit': $width = $this->options['w'] ?: $image->get_width(); $height = $this->options['h'] ?: $image->get_height(); if (is_numeric($width) && is_numeric($height)) { $image->best_fit($width, $height); } break; default: $width = $this->options['w']; $height = $this->options['h']; if (is_numeric($width) && is_numeric($height)) { $image->thumbnail($width, $height); } elseif (is_numeric($width)) { $image->fit_to_width($width); } elseif (is_numeric($height)) { $image->fit_to_height($height); } else { $width = $image->get_width(); $height = $image->get_height(); $image->thumbnail($width, $height); } } return $image; }
/** * Resize image * * @param string $imagePath * @param int $width * @param int $height * @throws \ImageTool\Model\ModelException */ public function resize($imagePath, $width, $height) { try { $simpleImage = new SimpleImage($imagePath); $simpleImage->resize($width, $height)->save(); } catch (Exception $e) { Log::get()->error('Failed to resize image.', $e); throw new ModelException('Failed to resize image.'); } }
/** * @return SimpleImage */ protected function create() { $image = new SimpleImage($this->file); $width = $this->options['w'] ?: $image->get_width(); $height = $this->options['h'] ?: $image->get_height(); switch ($this->options['strategy']) { case 'thumbnail': $image->resize($width, $height); break; case 'best_fit': $image->best_fit($width, $height); break; default: $image->thumbnail($width, $height); } return $image; }