From f3f36b421bb4fc530520685a94d06027ec28bce9 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Fri, 9 Aug 2013 16:28:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=83=D0=BA=D0=B0=D0=B7=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=D1=83=D0=BB=D1=8C=D1=82=D0=B8=D1=80=D1=83=D1=8E=D1=89?= =?UTF-8?q?=D0=B5=D0=B3=D0=BE=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20Upload.class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Upload.class.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Upload.class.php b/Upload.class.php index d0d736b..7f08ca8 100644 --- a/Upload.class.php +++ b/Upload.class.php @@ -16,10 +16,12 @@ abstract class Upload * @param $class string * @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...']) * @param $force_create_variants bool + * @param int $quality * @return Image * @throws ErrorException + * TODO: Рефакторинг: убрать параметр $force_create_variants */ - public static function image($class, $file, $force_create_variants = true) + public static function image($class, $file, $force_create_variants = true, $quality = 87) { /** * @var $image Image @@ -29,12 +31,12 @@ abstract class Upload $image->original_filename = $file['name']; $greagwar_image = self::getGreagwarImage($file['tmp_name']); - self::saveImage($image, $greagwar_image); + self::saveImage($image, $greagwar_image, null, null, true, $quality); if ($force_create_variants) { $sizes = $image->getSizes(); foreach ($sizes as $size) { $size_parts = explode('x', $size); - self::saveImage($image->getImageVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); + self::saveImage($image->getImageVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null, true, $quality); } } return $image; @@ -46,15 +48,16 @@ abstract class Upload * @param null $width * @param null $height * @param bool $crop TODO: разъяснить за что отвечает этот "магический" параметер + * @param int $quality */ - public static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true) + public static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true, $quality = 87) { $greagwar_image = clone($greagwar_image); if ($width || $height) { $greagwar_image->resize($width, $height, 0xffffff, false, false, $crop); } $image->type = $greagwar_image->guessType(); - $file_path = $greagwar_image->cacheFile($image->type, 87, true); + $file_path = $greagwar_image->cacheFile($image->type, $quality, true); $image->size = filesize($file_path); $path_parts = pathinfo($file_path); $image->path = preg_replace('#^' . Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']);