|
@ -16,10 +16,12 @@ abstract class Upload |
|
|
* @param $class string |
|
|
* @param $class string |
|
|
* @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...']) |
|
|
* @param $file array (ex. ['tmp_name' => '...', 'name' => '...', 'type' => '...']) |
|
|
* @param $force_create_variants bool |
|
|
* @param $force_create_variants bool |
|
|
|
|
|
* @param int $quality |
|
|
* @return Image |
|
|
* @return Image |
|
|
* @throws ErrorException |
|
|
* @throws ErrorException |
|
|
|
|
|
* TODO: Рефакторинг: убрать параметр $force_create_variants |
|
|
*/ |
|
|
*/ |
|
|
public static function image($class, $file, $force_create_variants = true) |
|
|
|
|
|
|
|
|
public static function image($class, $file, $force_create_variants = true, $quality = 87) |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
|
* @var $image Image |
|
|
* @var $image Image |
|
@ -29,12 +31,12 @@ abstract class Upload |
|
|
$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); |
|
|
|
|
|
|
|
|
self::saveImage($image, $greagwar_image, null, null, true, $quality); |
|
|
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); |
|
|
$size_parts = explode('x', $size); |
|
|
self::saveImage($image->getImageVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
|
|
|
|
|
|
self::saveImage($image->getImageVariant($size), $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null, true, $quality); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return $image; |
|
|
return $image; |
|
@ -46,15 +48,16 @@ abstract class Upload |
|
|
* @param null $width |
|
|
* @param null $width |
|
|
* @param null $height |
|
|
* @param null $height |
|
|
* @param bool $crop TODO: разъяснить за что отвечает этот "магический" параметер |
|
|
* @param bool $crop TODO: разъяснить за что отвечает этот "магический" параметер |
|
|
|
|
|
* @param int $quality |
|
|
*/ |
|
|
*/ |
|
|
public static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true) |
|
|
|
|
|
|
|
|
public static function saveImage($image, $greagwar_image, $width = null, $height = null, $crop = true, $quality = 87) |
|
|
{ |
|
|
{ |
|
|
$greagwar_image = clone($greagwar_image); |
|
|
$greagwar_image = clone($greagwar_image); |
|
|
if ($width || $height) { |
|
|
if ($width || $height) { |
|
|
$greagwar_image->resize($width, $height, 0xffffff, false, false, $crop); |
|
|
$greagwar_image->resize($width, $height, 0xffffff, false, false, $crop); |
|
|
} |
|
|
} |
|
|
$image->type = $greagwar_image->guessType(); |
|
|
$image->type = $greagwar_image->guessType(); |
|
|
$file_path = $greagwar_image->cacheFile($image->type, 87, true); |
|
|
|
|
|
|
|
|
$file_path = $greagwar_image->cacheFile($image->type, $quality, 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']); |
|
|