Попытка исправить утечку оперативной памяти N2
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* Class Upload
|
||||
* TODO: При загрузке изображений - использовать экземпляр класса. Убрать статику
|
||||
* @version 0.2
|
||||
*/
|
||||
abstract class Upload
|
||||
{
|
||||
@ -45,9 +45,7 @@ abstract class Upload
|
||||
}
|
||||
$image = is_object($class) ? $class : new $class;
|
||||
$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) {
|
||||
$sizes = $image->getSizes();
|
||||
foreach ($sizes as $size) {
|
||||
@ -60,17 +58,14 @@ abstract class Upload
|
||||
/**
|
||||
* @param $image Image
|
||||
* @param $size string @ex '1200x960'
|
||||
* @param $greagwar_image GreagwarImage
|
||||
* @param $greagwar_image GreagwarImage @deprecated
|
||||
*/
|
||||
public static function imageVariant($image, $size, $greagwar_image = null)
|
||||
{
|
||||
$image_variant = new ImageVariant();
|
||||
if (is_null($greagwar_image)) {
|
||||
$greagwar_image = self::getGreagwarImage(self::getFilePath($image));
|
||||
}
|
||||
$size_parts = explode('x', $size);
|
||||
self::saveImage($image_variant, $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null);
|
||||
unset($greagwar_image);
|
||||
$image_variant = new ImageVariant();
|
||||
$size_parts = explode('x', $size);
|
||||
self::saveImage($image_variant, self::getFilePath($image), $size_parts[0] ? : null, $size_parts[1] ? : null);
|
||||
$image->variants[$size] = $image_variant;
|
||||
if (Config::get('PYTHON_PIL_RESIZE')) {
|
||||
$script_file_path = Config::get('PYTHON_PIL_RESIZE')->script_file_path;
|
||||
@ -98,33 +93,44 @@ abstract class Upload
|
||||
|
||||
/**
|
||||
* @param $image ImageVariant|Image
|
||||
* @param $greagwar_image GreagwarImage
|
||||
* @param $tmp_file_path string|GreagwarImage
|
||||
* @param null $width
|
||||
* @param null $height
|
||||
* 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 (!(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 {
|
||||
$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);
|
||||
$path_parts = pathinfo($file_path);
|
||||
$image->path = preg_replace('#^' . Config::get('PATH_WEB_ROOT') . '/#', '', $path_parts['dirname']);
|
||||
$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')
|
||||
{
|
||||
$file_path = self::getFilePath($image);
|
||||
|
Reference in New Issue
Block a user