public function fit_to_height($height, $upscale = false) { if ($upscale === false && $height >= $this->image_class->get_height()) { return $this; } $this->image_class->fit_to_height($height); return $this; }
/** * @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); 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; } }
/** * Reduce image size and optimize the image quality * * @author salvipascual * @author kuma * @version 2.0 * @param String $imagePath, path to the image * @param number $width Fit to width * @param number $height Fit to height * @param number $quality Decrease/increase quality * @param string $format Convert to format * @return boolean */ public function optimizeImage($imagePath, $width = "", $height = "", $quality = 70, $format = 'image/jpeg') { if (!class_exists('SimpleImage')) { include_once "../lib/SimpleImage.php"; } try { $img = new SimpleImage(); $img->load($imagePath); if (!empty($width)) { $img->fit_to_width($width); } if (!empty($height)) { $img->fit_to_height($height); } $img->save($imagePath, $quality, $format); } catch (Exception $e) { return false; } return true; }