Browse Source

MIRSPORTA-73 - Качество картинок. Ресамплинг

Попытка избваиться от утечки памяти
master
Alexander Demidov 11 years ago
parent
commit
b59225c689
  1. 26
      Upload.class.php

26
Upload.class.php

@ -1,10 +1,14 @@
<?php
/**
* Class Upload
* TODO: При загрузке изображений - использовать экземпляр класса. Убрать статику
*/
abstract class Upload
{
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';
$greagwar_image = new GreagwarImage($file_path);
@ -44,6 +48,7 @@ abstract class Upload
$image->original_filename = $file['name'];
$greagwar_image = self::getGreagwarImage($file['tmp_name']);
self::saveImage($image, $greagwar_image, $class::getMaxWidth(), $class::getMaxHeight());
unset($greagwar_image);
if ($force_create_variants) {
$sizes = $image->getSizes();
foreach ($sizes as $size) {
@ -66,6 +71,7 @@ abstract class Upload
}
$size_parts = explode('x', $size);
self::saveImage($image_variant, $greagwar_image, $size_parts[0] ? : null, $size_parts[1] ? : null);
unset($greagwar_image);
$image->variants[$size] = $image_variant;
if (Config::get('PYTHON_PIL_RESIZE')) {
$script_file_path = Config::get('PYTHON_PIL_RESIZE')->script_file_path;
@ -88,25 +94,27 @@ abstract class Upload
* @param null $height
* 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 (!(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 {
$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);
$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->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')

Loading…
Cancel
Save