|
@ -69,33 +69,21 @@ 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) : ''; |
|
|
|
|
|
|
|
|
if (Config::get('PYTHON_PIL_PASTE') && |
|
|
|
|
|
function_exists(array($image, 'getWatermark')) && |
|
|
|
|
|
$image->getWatermark($size) |
|
|
|
|
|
) { |
|
|
|
|
|
$script_file_path = Config::get('PYTHON_PIL_PASTE')->script_file_path; |
|
|
|
|
|
$pil_options = (isset(Config::get('PYTHON_PIL_PASTE')->pil_options) && Config::get('PYTHON_PIL_PASTE')->pil_options) ? ' ' . implode(' ', Config::get('PYTHON_PIL_PASTE')->pil_options) : ''; |
|
|
// ob_start();
|
|
|
// 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)); |
|
|
|
|
|
|
|
|
passthru($script_file_path |
|
|
|
|
|
. $pil_options |
|
|
|
|
|
. ' ' . self::getFilePath($image_variant) |
|
|
|
|
|
. ' ' . Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size)); |
|
|
// ob_clean();
|
|
|
// ob_clean();
|
|
|
} |
|
|
|
|
|
if (Config::get('PYTHON_PIL_PASTE') && |
|
|
|
|
|
function_exists(array($image, 'getWatermark')) && |
|
|
|
|
|
$image->getWatermark($size) |
|
|
|
|
|
) { |
|
|
|
|
|
$script_file_path = Config::get('PYTHON_PIL_PASTE')->script_file_path; |
|
|
|
|
|
$pil_options = (isset(Config::get('PYTHON_PIL_PASTE')->pil_options) && Config::get('PYTHON_PIL_PASTE')->pil_options) ? ' ' . implode(' ', Config::get('PYTHON_PIL_PASTE')->pil_options) : ''; |
|
|
|
|
|
// ob_start();
|
|
|
|
|
|
passthru($script_file_path |
|
|
|
|
|
. $pil_options |
|
|
|
|
|
. ' ' . self::getFilePath($image_variant) |
|
|
|
|
|
. ' ' . Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size)); |
|
|
|
|
|
// 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,24 +104,41 @@ 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(); |
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
$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 (!(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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
$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']); |
|
|