|
@ -69,19 +69,6 @@ abstract class Upload |
|
|
$image_variant = new ImageVariant(); |
|
|
$image_variant = new ImageVariant(); |
|
|
$size_parts = explode('x', $size); |
|
|
$size_parts = explode('x', $size); |
|
|
self::saveImage($image_variant, self::getFilePath($image), $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
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; |
|
|
|
|
|
$pil_options = isset(Config::get('PYTHON_PIL_RESIZE')->pil_options) ? ' ' . implode(' ', Config::get('PYTHON_PIL_RESIZE')->pil_options) : ''; |
|
|
|
|
|
// ob_start();
|
|
|
|
|
|
passthru($script_file_path |
|
|
|
|
|
. (($size_parts[0])?' --width=' . $size_parts[0]:'') |
|
|
|
|
|
. (($size_parts[1])?' --height=' . $size_parts[1]:'') |
|
|
|
|
|
. $pil_options |
|
|
|
|
|
. ' ' . self::getFilePath($image) |
|
|
|
|
|
. ' ' . self::getFilePath($image_variant)); |
|
|
|
|
|
// ob_clean();
|
|
|
|
|
|
} |
|
|
|
|
|
if (Config::get('PYTHON_PIL_PASTE') && |
|
|
if (Config::get('PYTHON_PIL_PASTE') && |
|
|
function_exists(array($image, 'getWatermark')) && |
|
|
function_exists(array($image, 'getWatermark')) && |
|
|
$image->getWatermark($size) |
|
|
$image->getWatermark($size) |
|
@ -96,6 +83,7 @@ abstract class Upload |
|
|
// ob_clean();
|
|
|
// ob_clean();
|
|
|
} |
|
|
} |
|
|
self::defineSizeWidthAndHeight($image_variant); |
|
|
self::defineSizeWidthAndHeight($image_variant); |
|
|
|
|
|
$image->variants[$size] = $image_variant; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -103,7 +91,7 @@ abstract class Upload |
|
|
* @param $tmp_file_path string|GreagwarImage |
|
|
* @param $tmp_file_path string|GreagwarImage |
|
|
* @param null $width |
|
|
* @param null $width |
|
|
* @param null $height |
|
|
* @param null $height |
|
|
* TODO: Refactoring |
|
|
|
|
|
|
|
|
* TODO: Возможно, стоит искоренить GreagwarImage |
|
|
*/ |
|
|
*/ |
|
|
public static function saveImage($image, $tmp_file_path , $width = null, $height = null) |
|
|
public static function saveImage($image, $tmp_file_path , $width = null, $height = null) |
|
|
{ |
|
|
{ |
|
@ -116,8 +104,33 @@ abstract class Upload |
|
|
$greagwar_image = self::getGreagwarImage($tmp_file_path); |
|
|
$greagwar_image = self::getGreagwarImage($tmp_file_path); |
|
|
} |
|
|
} |
|
|
$image->type = $greagwar_image->guessType(); |
|
|
$image->type = $greagwar_image->guessType(); |
|
|
|
|
|
$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); |
|
|
|
|
|
} else { |
|
|
|
|
|
copy($tmp_file_path, $file_path); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
if (Config::get('PYTHON_PIL_RESIZE')) { |
|
|
|
|
|
$script_file_path = Config::get( 'PYTHON_PIL_RESIZE' )->script_file_path; |
|
|
|
|
|
$pil_options = isset( Config::get( 'PYTHON_PIL_RESIZE' )->pil_options ) ? ' ' . implode( ' ', 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; |
|
|
|
|
|
passthru( $command, $code ); |
|
|
|
|
|
if ($code !== 0) { |
|
|
|
|
|
throw new ErrorException('Command PYTHON_PIL_RESIZE: ' . $command ); |
|
|
|
|
|
} |
|
|
|
|
|
// ob_clean();
|
|
|
|
|
|
} else { |
|
|
if ($width || $height) { |
|
|
if ($width || $height) { |
|
|
if (!Config::get('PYTHON_PIL_RESIZE')) { |
|
|
|
|
|
if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { |
|
|
if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { |
|
|
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); |
|
|
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); |
|
|
} else { |
|
|
} else { |
|
@ -126,14 +139,6 @@ abstract class Upload |
|
|
$file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true); |
|
|
$file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (Config::get('PYTHON_PIL_RESIZE')) { |
|
|
|
|
|
$hash = $greagwar_image->getHash($image->type, $quality = 100); |
|
|
|
|
|
$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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
$path_parts = pathinfo($file_path); |
|
|
$path_parts = pathinfo($file_path); |
|
|
$image->path = preg_replace('#^' . Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']); |
|
|
$image->path = preg_replace('#^' . Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']); |
|
|