/**
  * @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;
     }
 }
Esempio n. 2
0
 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();
         }
     }
 }
Esempio n. 3
0
<?php

namespace abeautifulsite;

use Exception;
require '../src/abeautifulsite/SimpleImage.php';
try {
    // Flip the image and output it directly to the browser
    $img = new SimpleImage('butterfly.jpg');
    $img->flip('x')->output('png');
} catch (Exception $e) {
    echo '<span style="color: red;">' . $e->getMessage() . '</span>';
}
Esempio n. 4
0
$wtwidth = $watermarkSize[0];
$wtheight = $watermarkSize[1];
if ($mode === "single") {
    $img = new SimpleImage($img_main_path);
    $img->overlay($img_watmark_path, 'top left', $opacity, $posx, $posy);
    $img->save('../loadimg/' . $result_filename);
} else {
    $pozX = $posx;
    $pozY = $posy;
    $marX = $wmpadx;
    $marY = $wmpady;
    $widMain = $imagewidth;
    $heigMain = $imageheight;
    $widWat = $wtwidth;
    $heigWat = $wtheight;
    $img = new SimpleImage($img_main_path);
    $newPozX = $pozX;
    while ($newPozX < $widMain) {
        $newPozY = $pozY;
        while ($newPozY < $heigMain) {
            $img->overlay($img_watmark_path, 'top left', $opacity, $newPozX, $newPozY);
            $newPozY += $heigWat + $marX;
        }
        $newPozX += $widWat + $marY;
    }
    $img->save('../loadimg/' . $result_filename);
}
$uploadpath = "../loadimg/result.jpg";
exit($uploadpath);
/*$answer['1'] = $$img_watmark_path;
$answer['2'] = $imageheight;
Esempio n. 5
0
<?php

namespace abeautifulsite;

use Exception;
require '../src/abeautifulsite/SimpleImage.php';
if (!is_dir('processed/')) {
    mkdir('processed/');
}
try {
    // Create an image from scratch
    $img = new SimpleImage(null, 500, 200, '#FFCC00');
    $img->text('Dynamically Created Image', 'delicious.ttf');
    $img->save('processed/created-image.png');
    // If you use create function instead of loading image
    // you have to define output extension
    $img->output('png');
} catch (Exception $e) {
    echo '<span style="color: red;">' . $e->getMessage() . '</span>';
}
 public function save($filename = null, $quality = null, $format = null)
 {
     $this->image_class->save($filename, $quality, $format);
 }
Esempio n. 7
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;
 }
use Exception;
//test for the environment ... CLI versus browser
if (PHP_SAPI === 'cli') {
    $reldir = $argv[1];
    if (!isset($argv[1])) {
        exit("Must specify a directory to scan\n");
    }
    if (!is_dir($argv[1])) {
        exit($argv[1] . "' is not a directory\n");
    }
} else {
    die;
}
require 'SimpleImage.php';
$img = new SimpleImage();
$path_thumbs = $reldir . 'thumbs/';
$path_imgs = $reldir;
if (!is_dir($path_thumbs)) {
    mkdir($path_thumbs);
}
$allowed = array('gif', 'jpg', 'jpeg', 'png', 'ttf');
$dir_imgs = new \DirectoryIterator($path_imgs);
foreach ($dir_imgs as $fileinfo) {
    if (!$fileinfo->isDot() && $fileinfo->isFile() && in_array($fileinfo->getExtension(), $allowed)) {
        $name = $fileinfo->getFilename();
        $pathname = $path_imgs . $fileinfo->getFilename();
        echo $name . "\n";
        try {
            $img->load($pathname)->fit_to_height(300)->save($path_thumbs . $name);
        } catch (Exception $e) {
<?php

namespace abeautifulsite;

use Exception;
require 'src/abeautifulsite/SimpleImage.php';
$image = new SimpleImage("../images/post.jpg");
$archivo = $_GET['image'];
$image2 = new SimpleImage("uploads/" . $archivo);
$image2->best_fit(300, 300)->save('uploads/tmp_' . $archivo);
/*
$a_texto = explode(' ', $texto);
$tmp_text = "";

if(strlen($texto) > 100){
	if(strlen($texto) > 150){
		$y = 10;
	}
	else{
		$y = 2;
	}
}
else {
	$y = 1;
}

foreach ($a_texto as $txt) {
	if(strlen($txt)+strlen($tmp_text) < 35) {
		$tmp_text .= ' '.$txt;		
	} else{
		$image->text($tmp_text, 'font.ttf', 15, '#4D4D4D', 'center', 200, $y);
Esempio n. 10
0
 /**
  * @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;
     }
 }
Esempio n. 11
0
 protected function resizeImage($tempFilePath, $thumbnailParams, $thumbnailPath)
 {
     /**
      * https://github.com/eventviva/php-image-resize
      *
      * PHP must be enabled:
      * extension=php_mbstring.dll
      * extension=php_exif.dll
      *
      * // $image = new ImageResize ( $tempFilePath );
      * // $image->resizeToBestFit ( $thumbnailParams ['width'], $thumbnailParams ['height'] );
      * // $image->save ( $thumbnailPath );
      */
     try {
         $image = new SimpleImage();
         $image->load($tempFilePath)->best_fit($thumbnailParams['width'], $thumbnailParams['height'])->save($thumbnailPath);
     } catch (Exception $e) {
         throw new SystemException($e->getMessage());
     }
 }
Esempio n. 12
0
 /**
  * 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;
 }
Esempio n. 13
0
 /**
  * Crop image to dimensions
  *
  * @param string $imagePath
  * @param int $x1
  * @param int $y1
  * @param int $x2
  * @param int $y2
  * @throws \ImageTool\Model\ModelException
  */
 public function crop($imagePath, $x1, $y1, $x2, $y2)
 {
     try {
         $simpleImage = new SimpleImage($imagePath);
         $simpleImage->crop($x1, $y1, $x2, $y2)->save();
     } catch (Exception $e) {
         Log::get()->error('Failed to resize image.', $e);
         throw new ModelException('Failed to resize image.');
     }
 }
Esempio n. 14
0
<?php

namespace abeautifulsite;

use Exception;
require 'src/abeautifulsite/SimpleImage.php';
$image = new SimpleImage("../images/post.png");
$image->adaptive_resize(300, 300)->auto_orient()->save("prueba.png");
Esempio n. 15
0
 /**
  * Main processing script
  *
  * @throws Exception
  */
 public function processAction()
 {
     $this->view->disable();
     if ($this->request->isAjax()) {
         // Set transaction manager
         $transactionManager = new TransactionManager();
         $transaction = $transactionManager->get();
         $root = $this->root;
         $upload_dir_full = $this->upload_dir_full;
         $processed_dir = $this->processed_dir;
         // Create processed folder if it doesn't exist
         if (!file_exists($processed_dir)) {
             mkdir($processed_dir, 0777, true);
         }
         $qrs = $this->persistent->qrs;
         $errors = $this->persistent->errors;
         $created_prods_counter = $this->persistent->created_prods_counter;
         $created_prods_ids = $this->persistent->created_prods_ids;
         $id = $this->request->get('id');
         $item = self::filter($upload_dir_full, "{$id}")[$id];
         // A product must have a minimum of 3 photos
         if (count($item, true) - 1 < 4) {
             $this->errorExit($errors, $id, "У товара должно быть минимум три фотографии!");
         }
         // Check for file name (should not contain alphabetic characters)
         foreach ($item as $i => $f) {
             if (preg_match_all('/[A-Za-z]+\\d*\\./', "{$upload_dir_full}/{$f}")) {
                 $this->errorExit($errors, $id, "Неправильное название файла ({$f})");
             }
         }
         // QR code image
         $qrcode_img = $item[0];
         // Get scanned QR code
         if ($qrs[$id] != false) {
             $code = $qrs[$id];
         } else {
             $this->errorExit($errors, $id, "Не удалось отсканировать QR код ({$qrcode_img})");
         }
         // Check for product existence
         if (PProductMain::findFirst($code)) {
             $this->errorExit($errors, $id, "Товар с таким QR кодом уже внесен в базу ({$code})");
         }
         // -----------------------------------------------------------
         // QR code processing
         $qrcode_info = pathinfo($qrcode_img);
         $qrcode_name = "{$qrcode_info['filename']}qr{$code}";
         $qrcode_folder = rand(111, 999) . "/" . rand(1111111, 99999999) . "/";
         $width = getimagesize("{$upload_dir_full}/{$qrcode_img}")[0];
         $height = getimagesize("{$upload_dir_full}/{$qrcode_img}")[1];
         $filesize = filesize("{$upload_dir_full}/{$qrcode_img}");
         // Create folders for a QR code
         mkdir($root . $this->config->upload->media_qrcodeimage_folder . "/" . $qrcode_folder, 0777, true);
         mkdir($root . $this->config->upload->media_qrcodeimage_nail_folder . "/" . $qrcode_folder, 0777, true);
         // Copy QR code image to the respective folder
         if (!copy("{$upload_dir_full}/{$qrcode_img}", $root . $this->config->upload->media_qrcodeimage_folder . "/" . $qrcode_folder . $qrcode_name . "." . $qrcode_info['extension'])) {
             $this->errorExit($errors, $id, "Ошибка при копировании изображения QR кода ({$qrcode_img})");
         }
         $qrimg = new SimpleImage("{$upload_dir_full}/{$qrcode_img}");
         // Resize QR code image for a thumbnail (100 px) and copy it to nail folder
         if (!$qrimg->fit_to_width(100)->save($root . $this->config->upload->media_qrcodeimage_nail_folder . "/" . $qrcode_folder . $qrcode_name . "." . $qrcode_info['extension'])) {
             $this->errorExit($errors, $id, "Ошибка при копировании изображения (nail) QR кода ({$qrcode_img})");
         }
         // Add QR code to the db
         $qrcode = new PProdQrcodeimage();
         $qrcode->setTransaction($transaction);
         $qrcode->product_id = $code;
         $qrcode->uri = $qrcode_name;
         $qrcode->ext = $qrcode_info['extension'];
         $qrcode->width = $width;
         $qrcode->height = $height;
         $qrcode->filesize = $filesize;
         $qrcode->folder = $qrcode_folder;
         $qrcode->thumbnail = "/thumb/qrcodeimage/nail/{$qrcode_folder}{$qrcode_name}.{$qrcode_info['extension']}";
         $qrcode->ordered = $qrcode->ordered();
         $qrcode->created = time();
         $qrcode->updated = time();
         if (!$qrcode->create()) {
             $transactionManager->collectTransactions();
             // Clear transactions
             $this->errorExit($errors, $id, "Ошибка при добавлении QR кода в базу данных ({$qrcode_img})");
         }
         // Remove QR code from the array
         array_shift($item);
         // -----------------------------------------------------------
         // Photos processing
         $photo_counter = 1;
         foreach ($item as $img) {
             // A product can have a maximum of 5 photos
             if ($photo_counter > 5) {
                 break;
             }
             // Change photo orientation if needed
             //                self::changeOrientation("$upload_dir_full/$img");
             $img_info = pathinfo($img);
             $rand = rand(1111, 9999);
             $width = getimagesize("{$upload_dir_full}/{$img}")[0];
             $height = getimagesize("{$upload_dir_full}/{$img}")[1];
             $filesize = filesize("{$upload_dir_full}/{$img}");
             $img_name = "IMG_{$rand}_{$height}";
             $img_folder = rand(111, 999) . "/" . rand(1111111, 99999999) . "/";
             // Create folders
             mkdir($root . $this->config->upload->media_productphoto_folder . "/" . $img_folder, 0777, true);
             mkdir($root . $this->config->upload->media_productphoto_thumb_folder . "/" . $img_folder, 0777, true);
             mkdir($root . $this->config->upload->media_productphoto_nail_folder . "/" . $img_folder, 0777, true);
             // Resave an image to remove EXIF data
             if (self::removeExif("{$upload_dir_full}/{$img}") == false) {
                 $this->errorExit($errors, $id, "Ошибка при обработке фотографии ({$img})");
             }
             // Copy an image to the respective folder
             if (!copy("{$upload_dir_full}/{$img}", $root . $this->config->upload->media_productphoto_folder . "/" . $img_folder . $img_name . "." . $img_info['extension'])) {
                 $this->errorExit($errors, $id, "Ошибка при копировании фотографии ({$img})");
             }
             // Resize an image for a thumbnail (500 px) and copy it to thumb folder
             $thumb_img = new SimpleImage("{$upload_dir_full}/{$img}");
             if (!$thumb_img->fit_to_width(500)->save($root . $this->config->upload->media_productphoto_thumb_folder . "/" . $img_folder . $img_name . "." . $img_info['extension'])) {
                 $this->errorExit($errors, $id, "Ошибка при копировании фотографии (thumb) ({$img})");
             }
             // Resize an image for a thumbnail (100 px) and copy it to nail folder
             $nail_img = new SimpleImage("{$upload_dir_full}/{$img}");
             if (!$nail_img->fit_to_width(100)->save($root . $this->config->upload->media_productphoto_nail_folder . "/" . $img_folder . $img_name . "." . $img_info['extension'])) {
                 $this->errorExit($errors, $id, "Ошибка при копировании фотографии (nail) ({$img})");
             }
             // Add image to the db
             $imgdb = new PProdPhoto();
             $imgdb->setTransaction($transaction);
             $imgdb->uri = $img_name;
             $imgdb->ext = $img_info['extension'];
             $imgdb->width = $width;
             $imgdb->height = $height;
             $imgdb->filesize = $filesize;
             $imgdb->folder = $img_folder;
             $imgdb->thumbnail = "/thumb/productphoto/nail/{$img_folder}{$img_name}.{$img_info['extension']}";
             $imgdb->product_id = $code;
             $imgdb->ordered = $photo_counter;
             $imgdb->created = time();
             $imgdb->updated = time();
             if (!$imgdb->create()) {
                 $transactionManager->collectTransactions();
                 // Clear transactions
                 $this->errorExit($errors, $id, "Ошибка при добавлении фотографий в базу данных ({$img})");
             }
             $photo_counter++;
         }
         // Create a new product
         $product = new PProductMain();
         $product->setTransaction($transaction);
         $product->id = $code;
         $product->created = time();
         $product->updated = time();
         $product->new = 1;
         $product->hasphoto = 1;
         $product->qrcodeimage_id = $qrcode->id;
         $product->status = 0;
         if (!$product->create()) {
             $transactionManager->collectTransactions();
             // Clear transactions
             $this->errorExit($errors, $id, "Ошибка при создании товара (QR - {$code})");
         }
         // Complete the transaction
         if (!$transaction->commit()) {
             $this->errorExit($errors, $id, "Ошибка транзакции (QR - {$code})");
         }
         // Set stats
         $this->ProdInfoService->setStat('product_created', 'photoUploader', 'ru', $code);
         // Move QR code image
         rename("{$upload_dir_full}/{$qrcode_img}", "{$processed_dir}/{$qrcode_name}.{$qrcode_info['extension']}");
         // Clear thumb for QR code img
         //            if (file_exists("$upload_dir_full/thumbs/$qrcode_img")) unlink("$upload_dir_full/thumbs/$qrcode_img");
         foreach ($item as $img) {
             // Move images
             rename("{$upload_dir_full}/{$img}", "{$processed_dir}/{$img}");
             // Clear thumbs
             //                if (file_exists("$upload_dir_full/thumbs/$img")) unlink("$upload_dir_full/thumbs/$img");
         }
         // Remove the id from QRs list
         $qrs = $this->persistent->qrs;
         unset($qrs[$id]);
         // Update counter and list of ids
         $created_prods_counter++;
         $created_prods_ids[] = $code;
         $this->persistent->qrs = $qrs;
         $this->persistent->created_prods_counter = $created_prods_counter;
         $this->persistent->created_prods_ids = $created_prods_ids;
         // Hooray!
         echo "success";
     }
 }
$messages = ['ru' => ['small' => 'Слишком маленкий водяной знак!'], 'eng' => ['small' => 'Too small watermark!']];
//Задаем индекс файла
$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();
}
//Замощение ватермарка
Esempio n. 17
0
<?php

namespace abeautifulsite;

use Exception;
require '../src/abeautifulsite/SimpleImage.php';
if (!is_dir('processed/')) {
    mkdir('processed/');
}
try {
    //
    // WARNING: This will create a lot of images in the /processed folder
    //
    $img = new SimpleImage();
    // Create from scratch
    $img->create(200, 100, '#08c')->save('processed/create-from-scratch.png');
    // Convert to GIF
    $img->load('butterfly.jpg')->save('processed/butterfly-convert-to-gif.gif');
    // Strip exif data (just load and save)
    $img->load('butterfly.jpg')->save('processed/butterfly-strip-exif.jpg');
    // Flip horizontal
    $img->load('butterfly.jpg')->flip('x')->save('processed/butterfly-flip-horizontal.jpg');
    // Flip vertical
    $img->load('butterfly.jpg')->flip('y')->save('processed/butterfly-flip-vertical.jpg');
    // Flip both
    $img->load('butterfly.jpg')->flip('x')->flip('y')->save('processed/butterfly-flip-both.jpg');
    // Rotate 90
    $img->load('butterfly.jpg')->rotate(90)->save('processed/butterfly-rotate-90.jpg');
    // Auto-orient
    $img->load('butterfly.jpg')->auto_orient()->save('processed/butterfly-auto-orient.jpg');
    // Resize
Esempio n. 18
0
 protected function handle_image($data)
 {
     $image = null;
     if (request()->has('delete_image')) {
         $fullpath = public_path() . '/uploads/' . $image->image;
         @unlink($fullpath);
         $fullpath = null;
     }
     if (request()->hasFile('image')) {
         $image = request()->file('image');
         if ($image->isValid()) {
             $valid_ext = ['jpg', 'jpeg', 'gif', 'png', 'bmp'];
             $ext = $image->getClientOriginalExtension();
             if (in_array($ext, $valid_ext)) {
                 $fullpath = public_path() . '/uploads/' . $image->getClientOriginalName();
                 $target = $image->move(public_path() . '/uploads', $image->getClientOriginalName());
                 # RESIZE
                 if (file_exists($fullpath)) {
                     $newpath = public_path() . '/uploads/faq_' . $data->id . '.' . $ext;
                     if (file_exists($newpath)) {
                         @unlink($newpath);
                     }
                     $resize = new SimpleImage($fullpath);
                     $resize->best_fit(100, 100);
                     $resize->save($newpath);
                     @unlink($fullpath);
                     # SAVE IMAGE FILENAME
                     $data->image = 'faq_' . $data->id . '.' . $ext;
                     $data->save();
                 }
             } else {
             }
         }
     }
 }
Esempio n. 19
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;
 }
    $wtheight = $watermarkSize[1];
    if ($mode == "single") {
        $img = new SimpleImage($uploadfile);
        $img->overlay($watermarkfile, 'top left', $opacity, $originX, $originY);
        $img->save('./file/watermarked.jpg');
    } else {
        if ($mode == "tile") {
            $pozX = $originX;
            $pozY = $originY;
            $marX = $marginX;
            $marY = $marginY;
            $widMain = $imagewidth;
            $heigMain = $imageheight;
            $widWat = $wtwidth;
            $heigWat = $wtheight;
            $img = new SimpleImage($uploadfile);
            $newPozX = $pozX;
            while ($newPozX < $widMain) {
                $newPozY = $pozY;
                while ($newPozY < $heigMain) {
                    $img->overlay($watermarkfile, 'top left', $opacity, $newPozX, $newPozY);
                    $newPozY += $heigWat + $marX;
                }
                $newPozX += $widWat + $marY;
            }
            $img->save('./file/watermarked.jpg');
        }
    }
}
// else {
// 	echo "<h3>Ошибка! Не удалось загрузить файл на сервер!</h3>";