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;
 }
Example #2
0
 /**
  * @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;
 }
$img_index = date("U") . "-" . mt_rand(0, 1000);
//Путь записи результтата
$result_dir_loc = 'img/watermark/';
$result_name = 'result-' . $img_index . '.jpg';
$result_src_loc = $result_dir_loc . $result_name;
$result_dir = __DIR__ . '/../' . $result_dir_loc;
$result_src = __DIR__ . '/../' . $result_src_loc;
//Проверяем наличие папки
if (!file_exists($result_dir)) {
    mkdir($result_dir, 755);
    //Создание папки
}
//Склеивание изображений
$main_image = new SimpleImage('../' . $main_image_src);
$main_image_width = $main_image->get_width();
$main_image_height = $main_image->get_height();
$watermark = new SimpleImage('../' . $watermark_src);
$watermark_width = $watermark->get_width();
$watermark_height = $watermark->get_height();
//Масштабирование ватермарка
if ($main_image_width / $watermark_width < 1) {
    $watermark = $watermark->fit_to_width($main_image_width);
    $watermark_height = $watermark->get_height();
}
if ($main_image_height / $watermark_height < 1) {
    $watermark = $watermark->fit_to_height($main_image_height);
    $watermark_width = $watermark->get_width();
}
//Замощение ватермарка
if ($watermark_mode == 'grid-mode') {
    //Ограничение по соотношению изображений
Example #4
0
 /**
  * @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;
 }