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; }
public function upload_image($image, $properties) { // Filename $random_string = $properties['filename'] . '-' . str_replace(' ', '_', $image['name']); // Initialise SimpleImage $img = new SimpleImage($image['tmp_name']); // Get Properties $max_width = $properties['max_width']; // Check for min width if (isset($properties['min_width'])) { if ($img->get_width() < $properties['min_width']) { return false; } } // Resize image try { $img->fit_to_width($max_width); $img->save($this->upload_folder . '/' . $random_string); // Save the image to the_image $this->the_image = $this->public_folder . '/' . $random_string; } catch (Exception $e) { echo $e->getMessage(); // In a production app, the error should be logged or // sent to your own error handler/alert system and not // echoed out. } // Check to see if we need to generate thumbnail if (isset($properties['thumbnail'])) { // Get Properties $thumb_width = $properties['thumbnail']['width']; $thumb_height = $properties['thumbnail']['height']; // Generate thumbnail try { $img->adaptive_resize($thumb_width, $thumb_height); $img->save($this->upload_folder . '/thumbnails/' . $random_string); // Save the image to the_thumbnail $this->the_thumbnail = $this->public_folder . '/thumbnails/' . $random_string; } catch (Exception $e) { echo $e->getMessage(); } } }
/** * @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') {
/** * @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; }