From 8c82ae7ac4945a366602f6ecb8d5d0f7a78c6a65 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Wed, 23 Dec 2015 03:52:28 +0300 Subject: [PATCH] =?UTF-8?q?important=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=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=BF=D1=80=D0=B8=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D1=87=D0=B8=D0=B8=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D0=BC=D1=8B=D1=85=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=8D=D1=82=D0=BE=D0=B3=D0=BE=20=D1=83=D1=81=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=D0=B8=D0=B9=20MIRSPORTA-885=20=D0=93=D1=80=D1=83=D0=BF=D0=BF?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D1=84=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D1=84=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Image.php | 4 ++++ Upload.php | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Image.php b/Image.php index 0ff0073..411531f 100644 --- a/Image.php +++ b/Image.php @@ -84,6 +84,10 @@ abstract class Image extends File */ public function getVariant($size, $force_create = false, $important_create = false) { + if ($force_create && !$important_create && array_key_exists($size, $this->variants) && $this->variants[$size]['size'] === null) { + $important_create = true; + } + return parent::getImageVariant($size, $force_create, $important_create); } } \ No newline at end of file diff --git a/Upload.php b/Upload.php index e64ad50..908420f 100644 --- a/Upload.php +++ b/Upload.php @@ -109,7 +109,9 @@ abstract class Upload } else { $greagwar_image = self::getGreagwarImage($tmp_file_path); } + $image->type = $greagwar_image->guessType(); + if (!Image::getIsSubClass($image)) { if ( !( ImageVariant::getIsClass( $image ) ) && Image::getIsSubClass( $image ) ) { $greagwar_image->resize( $width, $height, 0xffffff, $force = false, $rescale = false, $crop = true ); @@ -117,8 +119,11 @@ abstract class Upload $greagwar_image->resize( $width, $height, 0xffffff, $force = false, $rescale = false, $crop = false ); } } + $hash = $greagwar_image->getHash($image->type, $quality = 100); + $file_path = $greagwar_image->generateFileFromhash($hash) . '.' . $image->type; + if (Image::getIsSubClass($image)) { if (is_uploaded_file($tmp_file_path)) { move_uploaded_file($tmp_file_path, $file_path); @@ -128,17 +133,24 @@ abstract class Upload } else { if (\Majestic\Config::get('PYTHON_PIL_RESIZE')) { $script_file_path = \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->script_file_path; + $pil_options = isset( \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) ? ' ' . implode( ' ', \Majestic\Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) : ''; + // ob_start(); + $code = null; + $command = $script_file_path . ( ( $width ) ? ' --width=' . $width : '' ) . ( ( $height ) ? ' --height=' . $height : '' ) . $pil_options . ' ' . $tmp_file_path . ' ' . $file_path; + ob_start(); + passthru( 'exec 2>&1; ' . $command, $code ); + if ($code !== 0) { throw new \ErrorException('Command PYTHON_PIL_RESIZE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); } @@ -149,10 +161,15 @@ abstract class Upload } } } + $path_parts = pathinfo($file_path); + $image->path = preg_replace('#^' . \Majestic\Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']); + $image->filename = $path_parts['basename']; + self::defineSizeWidthAndHeight($image); + unset($greagwar_image); }