|
@ -21,7 +21,7 @@ abstract class Upload |
|
|
* @throws ErrorException |
|
|
* @throws ErrorException |
|
|
* TODO: Рефакторинг: убрать параметр $force_create_variants |
|
|
* TODO: Рефакторинг: убрать параметр $force_create_variants |
|
|
*/ |
|
|
*/ |
|
|
public static function image($class, $file, $force_create_variants = true, $quality = 95) |
|
|
|
|
|
|
|
|
public static function image($class, $file, $force_create_variants = true) |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
|
* @var $image Image |
|
|
* @var $image Image |
|
@ -36,12 +36,11 @@ 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']); |
|
|
$greagwar_image = self::getGreagwarImage($file['tmp_name']); |
|
|
self::saveImage($image, $greagwar_image, $class::getMaxWidth(), $class::getMaxHeight(), $quality); |
|
|
|
|
|
|
|
|
self::saveImage($image, $greagwar_image, $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) { |
|
|
$size_parts = explode('x', $size); |
|
|
|
|
|
self::saveImage($image->getImageVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null, $quality); |
|
|
|
|
|
|
|
|
self::imageVariant($image, $size); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// В случае, если был передан объект, возвращение результата не имеет значения
|
|
|
// В случае, если был передан объект, возвращение результата не имеет значения
|
|
@ -49,14 +48,29 @@ abstract class Upload |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
|
|
|
* @param $image Image |
|
|
|
|
|
* @param $size string @ex '1200x960' |
|
|
|
|
|
* @param $greagwar_image GreagwarImage |
|
|
|
|
|
*/ |
|
|
|
|
|
public static function imageVariant($image, $size, $greagwar_image = null) |
|
|
|
|
|
{ |
|
|
|
|
|
$image_variant = new ImageVariant(); |
|
|
|
|
|
if (is_null($greagwar_image)) { |
|
|
|
|
|
$greagwar_image = self::getGreagwarImage($image->path . DIRECTORY_SEPARATOR . $image->filename); |
|
|
|
|
|
} |
|
|
|
|
|
$size_parts = explode('x', $size); |
|
|
|
|
|
self::saveImage($image_variant, $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
|
|
|
$image->variants[$size] = $image_variant; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
* @param $image ImageVariant|Image |
|
|
* @param $image ImageVariant|Image |
|
|
* @param $greagwar_image GreagwarImage |
|
|
* @param $greagwar_image GreagwarImage |
|
|
* @param null $width |
|
|
* @param null $width |
|
|
* @param null $height |
|
|
* @param null $height |
|
|
* @param int $quality |
|
|
|
|
|
* TODO: Сделать возможность передавать параметры для метода _resize() |
|
|
* TODO: Сделать возможность передавать параметры для метода _resize() |
|
|
*/ |
|
|
*/ |
|
|
public static function saveImage($image, $greagwar_image, $width = null, $height = null, $quality = 95) |
|
|
|
|
|
|
|
|
public static function saveImage($image, $greagwar_image, $width = null, $height = null) |
|
|
{ |
|
|
{ |
|
|
$greagwar_image = clone($greagwar_image); |
|
|
$greagwar_image = clone($greagwar_image); |
|
|
if ($width || $height) { |
|
|
if ($width || $height) { |
|
@ -67,7 +81,7 @@ abstract class Upload |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$image->type = $greagwar_image->guessType(); |
|
|
$image->type = $greagwar_image->guessType(); |
|
|
$file_path = $greagwar_image->cacheFile($image->type, $quality, true); |
|
|
|
|
|
|
|
|
$file_path = $greagwar_image->cacheFile($image->type, $quality = 95, 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']); |
|
|