|
|
@ -11,16 +11,16 @@ abstract class Upload |
|
|
|
|
|
|
|
public static function &getGreagwarImage($file_path) |
|
|
|
{ |
|
|
|
$greagwar_image = new GreagwarImage($file_path); |
|
|
|
$config_upload = Config::get('Upload'); |
|
|
|
$greagwar_image = new \GreagwarImage($file_path); |
|
|
|
$config_upload = \Majestic\Config::get('Upload'); |
|
|
|
$dir_image_cache = $config_upload ? $config_upload->dir_image_cache : self::$dir_image_cache; |
|
|
|
$greagwar_image->setCacheDir(Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $dir_image_cache); |
|
|
|
$greagwar_image->setCacheDir(\Majestic\Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $dir_image_cache); |
|
|
|
return $greagwar_image; |
|
|
|
} |
|
|
|
|
|
|
|
public static function getFilePath($image) |
|
|
|
{ |
|
|
|
return Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $image->path . DIRECTORY_SEPARATOR . $image->filename; |
|
|
|
return \Majestic\Config::get('PATH_WEB_ROOT') . DIRECTORY_SEPARATOR . $image->path . DIRECTORY_SEPARATOR . $image->filename; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -37,10 +37,10 @@ abstract class Upload |
|
|
|
* @var $image Image |
|
|
|
*/ |
|
|
|
if (is_null($class) || $class == '') { |
|
|
|
throw new ErrorException('Class not defined.'); |
|
|
|
throw new \ErrorException('Class not defined.'); |
|
|
|
} |
|
|
|
if (!is_object($class) && !class_exists($class)) { |
|
|
|
throw new ErrorException('Class "' . $class . '" not exists.'); |
|
|
|
throw new \ErrorException('Class "' . $class . '" not exists.'); |
|
|
|
} |
|
|
|
Image::checkSubClass($class); |
|
|
|
if (isset($file['error']) && $file['error'] != 0) { |
|
|
@ -62,7 +62,7 @@ abstract class Upload |
|
|
|
/** |
|
|
|
* @param $image Image |
|
|
|
* @param $size string @ex '1200x960' |
|
|
|
* @param $greagwar_image GreagwarImage @deprecated |
|
|
|
* @param $greagwar_image \GreagwarImage @deprecated |
|
|
|
*/ |
|
|
|
public static function imageVariant($image, $size, $greagwar_image = null) |
|
|
|
{ |
|
|
@ -70,21 +70,21 @@ abstract class Upload |
|
|
|
$image_variant = new ImageVariant(); |
|
|
|
$size_parts = explode('x', $size); |
|
|
|
self::saveImage($image_variant, self::getFilePath($image), $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
|
if (Config::get('PYTHON_PIL_PASTE') && |
|
|
|
if (\Majestic\Config::get('PYTHON_PIL_PASTE') && |
|
|
|
method_exists($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) : ''; |
|
|
|
$script_file_path = \Majestic\Config::get('PYTHON_PIL_PASTE')->script_file_path; |
|
|
|
$pil_options = (isset(\Majestic\Config::get('PYTHON_PIL_PASTE')->pil_options) && \Majestic\Config::get('PYTHON_PIL_PASTE')->pil_options) ? ' ' . implode(' ', \Majestic\Config::get('PYTHON_PIL_PASTE')->pil_options) : ''; |
|
|
|
ob_start(); |
|
|
|
$code = null; |
|
|
|
$command = $script_file_path |
|
|
|
. $pil_options |
|
|
|
. ' ' . self::getFilePath($image_variant) |
|
|
|
. ' ' . Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size); |
|
|
|
. ' ' . \Majestic\Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size); |
|
|
|
passthru('exec 2>&1; ' . $command, $code); |
|
|
|
if ($code !== 0) { |
|
|
|
throw new ErrorException('Command PYTHON_PIL_PASTE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); |
|
|
|
throw new \ErrorException('Command PYTHON_PIL_PASTE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); |
|
|
|
} |
|
|
|
ob_end_clean(); |
|
|
|
} |
|
|
@ -94,7 +94,7 @@ abstract class Upload |
|
|
|
|
|
|
|
/** |
|
|
|
* @param $image ImageVariant|Image |
|
|
|
* @param $tmp_file_path string|GreagwarImage |
|
|
|
* @param $tmp_file_path string|\GreagwarImage |
|
|
|
* @param null $width |
|
|
|
* @param null $height |
|
|
|
* TODO: Возможно, стоит искоренить GreagwarImage |
|
|
@ -126,9 +126,9 @@ abstract class Upload |
|
|
|
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 ) : ''; |
|
|
|
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 |
|
|
@ -140,7 +140,7 @@ abstract class Upload |
|
|
|
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() ); |
|
|
|
throw new \ErrorException('Command PYTHON_PIL_RESIZE exit with code "' . $code . '": ' . $command . PHP_EOL . 'Std out: ' . ob_get_clean() ); |
|
|
|
} |
|
|
|
ob_end_clean(); |
|
|
|
} else { |
|
|
@ -175,7 +175,7 @@ abstract class Upload |
|
|
|
$output = shell_exec("convert {$file_path} -brightness-contrast {$value} {$file_path} 2>&1"); |
|
|
|
if (isset($output) && $output) { |
|
|
|
if (class_exists('ErrorMessage')) { |
|
|
|
ErrorMessage::log($output); |
|
|
|
\ErrorMessage::log($output); |
|
|
|
} |
|
|
|
} |
|
|
|
} |