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); }