public function thumbnail($width, $height = null, $upscale = false) { if ($upscale === false && ($width >= $this->image_class->get_width() || $height >= $this->image_class->get_height())) { return $this; } $this->image_class->thumbnail($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; }
/** * @param string $source * @param array $options * @return bool|mixed */ protected function resizeImage($source, $options) { try { $image_path = App::locator()->get($source); $cachepath = $this->getCachePath($image_path, $options); if (!file_exists($cachepath)) { $image = new SimpleImage($image_path); if (!empty($options['width']) && empty($options['height'])) { $image->fit_to_width($options['width']); } if (!empty($options['height']) && empty($options['width'])) { $image->fit_to_height($options['height']); } if (!empty($options['height']) && !empty($options['width'])) { $image->thumbnail($options['width'], $options['height']); } $image->save($cachepath); } return $this->basePath($cachepath); } catch (\Exception $e) { return false; } }
/** * @param string $source * @param array $options * @return bool|mixed */ protected function resizeImage($source, $options) { try { $cachepath = $this->getCachePath($source, $options); if (!file_exists($cachepath)) { $image = new SimpleImage(App::path() . '/' . $source); if (!empty($options['width']) && empty($options['height'])) { $image->fit_to_width($options['width']); } if (!empty($options['height']) && empty($options['width'])) { $image->fit_to_height($options['height']); } if (!empty($options['height']) && !empty($options['width'])) { $image->thumbnail($options['width'], $options['height']); } $image->save($cachepath); } return trim(str_replace(App::path(), '', $cachepath), '/'); } catch (\Exception $e) { return false; } }
/** * @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; }