From cf7ba9d2acdee40f07d2c4247c8d92c6b7600e4a Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Fri, 27 Dec 2013 19:23:15 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20=D1=83?= =?UTF-8?q?=D1=82=D0=B5=D1=87=D0=BA=D1=83=20=D0=BE=D0=BF=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D0=B9=20=D0=BF=D0=B0=D0=BC=D1=8F?= =?UTF-8?q?=D1=82=D0=B8=20N2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Upload.class.php | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/Upload.class.php b/Upload.class.php index 7ba4f8c..5d800bf 100644 --- a/Upload.class.php +++ b/Upload.class.php @@ -2,7 +2,7 @@ /** * Class Upload - * TODO: При загрузке изображений - использовать экземпляр класса. Убрать статику + * @version 0.2 */ abstract class Upload { @@ -45,9 +45,7 @@ abstract class Upload } $image = is_object($class) ? $class : new $class; $image->original_filename = $file['name']; - $greagwar_image = self::getGreagwarImage($file['tmp_name']); - self::saveImage($image, $greagwar_image, $class::getMaxWidth(), $class::getMaxHeight()); - unset($greagwar_image); + self::saveImage($image, $file['tmp_name'], $class::getMaxWidth(), $class::getMaxHeight()); if ($force_create_variants) { $sizes = $image->getSizes(); foreach ($sizes as $size) { @@ -60,17 +58,14 @@ abstract class Upload /** * @param $image Image * @param $size string @ex '1200x960' - * @param $greagwar_image GreagwarImage + * @param $greagwar_image GreagwarImage @deprecated */ public static function imageVariant($image, $size, $greagwar_image = null) { + unset($greagwar_image); $image_variant = new ImageVariant(); - if (is_null($greagwar_image)) { - $greagwar_image = self::getGreagwarImage(self::getFilePath($image)); - } $size_parts = explode('x', $size); - self::saveImage($image_variant, $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); - unset($greagwar_image); + self::saveImage($image_variant, self::getFilePath($image), $size_parts[0] ? : null, $size_parts[1] ? : null); $image->variants[$size] = $image_variant; if (Config::get('PYTHON_PIL_RESIZE')) { $script_file_path = Config::get('PYTHON_PIL_RESIZE')->script_file_path; @@ -98,33 +93,44 @@ abstract class Upload /** * @param $image ImageVariant|Image - * @param $greagwar_image GreagwarImage + * @param $tmp_file_path string|GreagwarImage * @param null $width * @param null $height * TODO: Сделать возможность передавать параметры для метода _resize() */ - public static function saveImage($image, $greagwar_image , $width = null, $height = null) + public static function saveImage($image, $tmp_file_path , $width = null, $height = null) { - $greagwar_image_clone = clone($greagwar_image); - unset($greagwar_image); + if (is_object($tmp_file_path)) { + /** + * @deprecated + */ + $greagwar_image = $tmp_file_path; + } else { + $greagwar_image = self::getGreagwarImage(self::getFilePath($tmp_file_path)); + } if ($width || $height) { if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { - $greagwar_image_clone->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); + $greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); } else { - $greagwar_image_clone->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false); + $greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false); } } - $image->type = $greagwar_image_clone->guessType(); - $file_path = $greagwar_image_clone->cacheFile($image->type, $quality = 100, true); + $image->type = $greagwar_image->guessType(); + $file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true); $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_clone->width(); - $image->height = $greagwar_image_clone->height(); - unset($greagwar_image_clone); + $image->width = $greagwar_image->width(); + $image->height = $greagwar_image->height(); + unset($greagwar_image); } + /** + * @param $image + * @param string $value + * @deprecated + */ public static function brightnessContrast($image, $value = '0x7') { $file_path = self::getFilePath($image);