Browse Source

Разделение логики для обработки изображений GreagwarImage и PythonLibs/Image

master
Alexander Demidov 10 years ago
parent
commit
153cd49d1d
  1. 32
      Upload.class.php

32
Upload.class.php

@ -48,6 +48,7 @@ abstract class Upload
$image = is_object($class) ? $class : new $class;
$image->original_filename = $file['name'];
self::saveImage($image, $file['tmp_name'], $class::getMaxWidth(), $class::getMaxHeight());
self::defineSizeWidthAndHeight($image);
if ($force_create_variants) {
$sizes = $image->getSizes();
foreach ($sizes as $size) {
@ -94,6 +95,7 @@ abstract class Upload
. ' ' . Config::get('PATH_WEB_ROOT') . '/' . $image->getWatermark($size));
// ob_clean();
}
self::defineSizeWidthAndHeight($image_variant);
}
/**
@ -101,7 +103,7 @@ abstract class Upload
* @param $tmp_file_path string|GreagwarImage
* @param null $width
* @param null $height
* TODO: Сделать возможность передавать параметры для метода _resize()
* TODO: Refactoring
*/
public static function saveImage($image, $tmp_file_path , $width = null, $height = null)
{
@ -114,28 +116,40 @@ abstract class Upload
$greagwar_image = self::getGreagwarImage($tmp_file_path);
}
$image->type = $greagwar_image->guessType();
if (!Config::get('PYTHON_PIL_RESIZE')) {
if ($width || $height) {
if ($width || $height) {
if (!Config::get('PYTHON_PIL_RESIZE')) {
if (!(ImageVariant::getIsClass($image)) && Image::getIsSubClass($image)) {
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = true);
} else {
$greagwar_image->resize($width, $height, 0xffffff, $force = false, $rescale = false, $crop = false);
}
$file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true);
}
$file_path = $greagwar_image->cacheFile($image->type, $quality = 100, true);
} else {
}
if (Config::get('PYTHON_PIL_RESIZE')) {
$hash = $greagwar_image->getHash($image->type, $quality = 100);
$file_path = $greagwar_image->generateFileFromhash($hash);
$file_path = $greagwar_image->generateFileFromhash($hash) . '.' . $image->type;
if (is_uploaded_file($tmp_file_path)) {
move_uploaded_file($tmp_file_path, $file_path);
} else {
copy($tmp_file_path, $file_path);
}
}
$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();
unset($greagwar_image);
}
private static function defineSizeWidthAndHeight($image)
{
$file_path = self::getFilePath($image);
$imagesize = getimagesize($file_path);
$image->width = $imagesize[0];
$image->height = $imagesize[1];
$image->size = filesize($file_path);
}
/**
* @param $image
* @param string $value

Loading…
Cancel
Save