From 153cd49d1dcea5365e0215b75fd97361f508daae Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Thu, 15 May 2014 16:20:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B8=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B9=20GreagwarImage=20=D0=B8=20PythonLibs/Image?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Upload.class.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Upload.class.php b/Upload.class.php index 2c14dd2..158076f 100644 --- a/Upload.class.php +++ b/Upload.class.php @@ -48,6 +48,7 @@ abstract class Upload $image = is_object($class) ? $class : new $class; $image->original_filename = $file['name']; self::saveImage($image, $file['tmp_name'], $class::getMaxWidth(), $class::getMaxHeight()); + self::defineSizeWidthAndHeight($image); if ($force_create_variants) { $sizes = $image->getSizes(); foreach ($sizes as $size) { @@ -94,6 +95,7 @@ abstract class Upload . ' ' . Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size)); // ob_clean(); } + self::defineSizeWidthAndHeight($image_variant); } /** @@ -101,7 +103,7 @@ abstract class Upload * @param $tmp_file_path string|GreagwarImage * @param null $width * @param null $height - * TODO: Сделать возможность передавать параметры для метода _resize() + * TODO: Refactoring */ public static function saveImage($image, $tmp_file_path , $width = null, $height = null) { @@ -114,28 +116,40 @@ abstract class Upload $greagwar_image = self::getGreagwarImage($tmp_file_path); } $image->type = $greagwar_image->guessType(); - if (!Config::get('PYTHON_PIL_RESIZE')) { - if ($width || $height) { + if ($width || $height) { + if (!Config::get('PYTHON_PIL_RESIZE')) { if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { $greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); } else { $greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false); } + $file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true); } - $file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true); - } else { + } + if (Config::get('PYTHON_PIL_RESIZE')) { $hash = $greagwar_image->getHash($image->type, $quality = 100); - $file_path = $greagwar_image->generateFileFromhash($hash); + $file_path = $greagwar_image->generateFileFromhash($hash) . '.' . $image->type; + if (is_uploaded_file($tmp_file_path)) { + move_uploaded_file($tmp_file_path, $file_path); + } else { + copy($tmp_file_path, $file_path); + } } - $image->size = filesize($file_path); $path_parts = pathinfo($file_path); $image->path = preg_replace('#^' . Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']); $image->filename = $path_parts['basename']; - $image->width = $greagwar_image->width(); - $image->height = $greagwar_image->height(); unset($greagwar_image); } + private static function defineSizeWidthAndHeight($image) + { + $file_path = self::getFilePath($image); + $imagesize = getimagesize($file_path); + $image->width = $imagesize[0]; + $image->height = $imagesize[1]; + $image->size = filesize($file_path); + } + /** * @param $image * @param string $value