|
@ -2,7 +2,7 @@ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Class Upload |
|
|
* Class Upload |
|
|
* TODO: При загрузке изображений - использовать экземпляр класса. Убрать статику |
|
|
|
|
|
|
|
|
* @version 0.2 |
|
|
*/ |
|
|
*/ |
|
|
abstract class Upload |
|
|
abstract class Upload |
|
|
{ |
|
|
{ |
|
@ -45,9 +45,7 @@ abstract class Upload |
|
|
} |
|
|
} |
|
|
$image = is_object($class) ? $class : new $class; |
|
|
$image = is_object($class) ? $class : new $class; |
|
|
$image->original_filename = $file['name']; |
|
|
$image->original_filename = $file['name']; |
|
|
$greagwar_image = self::getGreagwarImage($file['tmp_name']); |
|
|
|
|
|
self::saveImage($image, $greagwar_image, $class::getMaxWidth(), $class::getMaxHeight()); |
|
|
|
|
|
unset($greagwar_image); |
|
|
|
|
|
|
|
|
self::saveImage($image, $file['tmp_name'], $class::getMaxWidth(), $class::getMaxHeight()); |
|
|
if ($force_create_variants) { |
|
|
if ($force_create_variants) { |
|
|
$sizes = $image->getSizes(); |
|
|
$sizes = $image->getSizes(); |
|
|
foreach ($sizes as $size) { |
|
|
foreach ($sizes as $size) { |
|
@ -60,17 +58,14 @@ abstract class Upload |
|
|
/** |
|
|
/** |
|
|
* @param $image Image |
|
|
* @param $image Image |
|
|
* @param $size string @ex '1200x960' |
|
|
* @param $size string @ex '1200x960' |
|
|
* @param $greagwar_image GreagwarImage |
|
|
|
|
|
|
|
|
* @param $greagwar_image GreagwarImage @deprecated |
|
|
*/ |
|
|
*/ |
|
|
public static function imageVariant($image, $size, $greagwar_image = null) |
|
|
public static function imageVariant($image, $size, $greagwar_image = null) |
|
|
{ |
|
|
{ |
|
|
|
|
|
unset($greagwar_image); |
|
|
$image_variant = new ImageVariant(); |
|
|
$image_variant = new ImageVariant(); |
|
|
if (is_null($greagwar_image)) { |
|
|
|
|
|
$greagwar_image = self::getGreagwarImage(self::getFilePath($image)); |
|
|
|
|
|
} |
|
|
|
|
|
$size_parts = explode('x', $size); |
|
|
$size_parts = explode('x', $size); |
|
|
self::saveImage($image_variant, $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
|
|
|
unset($greagwar_image); |
|
|
|
|
|
|
|
|
self::saveImage($image_variant, self::getFilePath($image), $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
$image->variants[$size] = $image_variant; |
|
|
$image->variants[$size] = $image_variant; |
|
|
if (Config::get('PYTHON_PIL_RESIZE')) { |
|
|
if (Config::get('PYTHON_PIL_RESIZE')) { |
|
|
$script_file_path = Config::get('PYTHON_PIL_RESIZE')->script_file_path; |
|
|
$script_file_path = Config::get('PYTHON_PIL_RESIZE')->script_file_path; |
|
@ -98,33 +93,44 @@ abstract class Upload |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* @param $image ImageVariant|Image |
|
|
* @param $image ImageVariant|Image |
|
|
* @param $greagwar_image GreagwarImage |
|
|
|
|
|
|
|
|
* @param $tmp_file_path string|GreagwarImage |
|
|
* @param null $width |
|
|
* @param null $width |
|
|
* @param null $height |
|
|
* @param null $height |
|
|
* TODO: Сделать возможность передавать параметры для метода _resize() |
|
|
* TODO: Сделать возможность передавать параметры для метода _resize() |
|
|
*/ |
|
|
*/ |
|
|
public static function saveImage($image, $greagwar_image , $width = null, $height = null) |
|
|
|
|
|
|
|
|
public static function saveImage($image, $tmp_file_path , $width = null, $height = null) |
|
|
{ |
|
|
{ |
|
|
$greagwar_image_clone = clone($greagwar_image); |
|
|
|
|
|
unset($greagwar_image); |
|
|
|
|
|
|
|
|
if (is_object($tmp_file_path)) { |
|
|
|
|
|
/** |
|
|
|
|
|
* @deprecated |
|
|
|
|
|
*/ |
|
|
|
|
|
$greagwar_image = $tmp_file_path; |
|
|
|
|
|
} else { |
|
|
|
|
|
$greagwar_image = self::getGreagwarImage(self::getFilePath($tmp_file_path)); |
|
|
|
|
|
} |
|
|
if ($width || $height) { |
|
|
if ($width || $height) { |
|
|
if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { |
|
|
if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { |
|
|
$greagwar_image_clone->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); |
|
|
|
|
|
|
|
|
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); |
|
|
} else { |
|
|
} else { |
|
|
$greagwar_image_clone->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false); |
|
|
|
|
|
|
|
|
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$image->type = $greagwar_image_clone->guessType(); |
|
|
|
|
|
$file_path = $greagwar_image_clone->cacheFile($image->type, $quality = 100, true); |
|
|
|
|
|
|
|
|
$image->type = $greagwar_image->guessType(); |
|
|
|
|
|
$file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true); |
|
|
$image->size = filesize($file_path); |
|
|
$image->size = filesize($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']); |
|
|
$image->filename = $path_parts['basename']; |
|
|
$image->filename = $path_parts['basename']; |
|
|
$image->width = $greagwar_image_clone->width(); |
|
|
|
|
|
$image->height = $greagwar_image_clone->height(); |
|
|
|
|
|
unset($greagwar_image_clone); |
|
|
|
|
|
|
|
|
$image->width = $greagwar_image->width(); |
|
|
|
|
|
$image->height = $greagwar_image->height(); |
|
|
|
|
|
unset($greagwar_image); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @param $image |
|
|
|
|
|
* @param string $value |
|
|
|
|
|
* @deprecated |
|
|
|
|
|
*/ |
|
|
public static function brightnessContrast($image, $value = '0x7') |
|
|
public static function brightnessContrast($image, $value = '0x7') |
|
|
{ |
|
|
{ |
|
|
$file_path = self::getFilePath($image); |
|
|
$file_path = self::getFilePath($image); |
|
|