|
@ -1,10 +1,14 @@ |
|
|
<?php |
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* Class Upload |
|
|
|
|
|
* TODO: При загрузке изображений - использовать экземпляр класса. Убрать статику |
|
|
|
|
|
*/ |
|
|
abstract class Upload |
|
|
abstract class Upload |
|
|
{ |
|
|
{ |
|
|
public static $dir_image_cache = 'media/cache/images'; |
|
|
public static $dir_image_cache = 'media/cache/images'; |
|
|
|
|
|
|
|
|
public static function getGreagwarImage($file_path) |
|
|
|
|
|
|
|
|
public static function &getGreagwarImage($file_path) |
|
|
{ |
|
|
{ |
|
|
require_once PATH . '/lib/GreagwarImage/GreagwarImage.php'; |
|
|
require_once PATH . '/lib/GreagwarImage/GreagwarImage.php'; |
|
|
$greagwar_image = new GreagwarImage($file_path); |
|
|
$greagwar_image = new GreagwarImage($file_path); |
|
@ -44,6 +48,7 @@ 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, $class::getMaxWidth(), $class::getMaxHeight()); |
|
|
self::saveImage($image, $greagwar_image, $class::getMaxWidth(), $class::getMaxHeight()); |
|
|
|
|
|
unset($greagwar_image); |
|
|
if ($force_create_variants) { |
|
|
if ($force_create_variants) { |
|
|
$sizes = $image->getSizes(); |
|
|
$sizes = $image->getSizes(); |
|
|
foreach ($sizes as $size) { |
|
|
foreach ($sizes as $size) { |
|
@ -66,6 +71,7 @@ abstract class Upload |
|
|
} |
|
|
} |
|
|
$size_parts = explode('x', $size); |
|
|
$size_parts = explode('x', $size); |
|
|
self::saveImage($image_variant, $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
self::saveImage($image_variant, $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null); |
|
|
|
|
|
unset($greagwar_image); |
|
|
$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,25 +104,27 @@ abstract class Upload |
|
|
* @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, $greagwar_image , $width = null, $height = null) |
|
|
{ |
|
|
{ |
|
|
$greagwar_image = clone($greagwar_image); |
|
|
|
|
|
|
|
|
$greagwar_image_clone = clone($greagwar_image); |
|
|
|
|
|
unset($greagwar_image); |
|
|
if ($width || $height) { |
|
|
if ($width || $height) { |
|
|
if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { |
|
|
if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) { |
|
|
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); |
|
|
|
|
|
|
|
|
$greagwar_image_clone->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true); |
|
|
} else { |
|
|
} else { |
|
|
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false); |
|
|
|
|
|
|
|
|
$greagwar_image_clone->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$image->type = $greagwar_image->guessType(); |
|
|
|
|
|
$file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true); |
|
|
|
|
|
|
|
|
$image->type = $greagwar_image_clone->guessType(); |
|
|
|
|
|
$file_path = $greagwar_image_clone->cacheFile($image->type, $quality = 100, true); |
|
|
chmod($file_path, 0664); |
|
|
chmod($file_path, 0664); |
|
|
$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->width(); |
|
|
|
|
|
$image->height = $greagwar_image->height(); |
|
|
|
|
|
|
|
|
$image->width = $greagwar_image_clone->width(); |
|
|
|
|
|
$image->height = $greagwar_image_clone->height(); |
|
|
|
|
|
unset($greagwar_image_clone); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static function brightnessContrast($image, $value = '0x7') |
|
|
public static function brightnessContrast($image, $value = '0x7') |
|
|