Browse Source

Качество jpeg по-умолчанию - 95. Изменен алгоритм ресайзинга (добавление белых полосок) - отключен для изображений-оргиналов. (не проверено)

master
Alexander Demidov 11 years ago
parent
commit
13b2dbd2b0
  1. 2
      Image.class.php
  2. 15
      Upload.class.php

2
Image.class.php

@ -1,6 +1,6 @@
<?php <?php
class Image extends File
abstract class Image extends File
{ {
public $width; public $width;
public $height; public $height;

15
Upload.class.php

@ -21,7 +21,7 @@ abstract class Upload
* @throws ErrorException * @throws ErrorException
* TODO: Рефакторинг: убрать параметр $force_create_variants * TODO: Рефакторинг: убрать параметр $force_create_variants
*/ */
public static function image($class, $file, $force_create_variants = true, $quality = 87)
public static function image($class, $file, $force_create_variants = true, $quality = 95)
{ {
/** /**
* @var $image Image * @var $image Image
@ -35,7 +35,6 @@ abstract class Upload
Image::checkSubClass($class); Image::checkSubClass($class);
$image = is_object($class) ? $class : new $class; $image = is_object($class) ? $class : new $class;
$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(), $quality); self::saveImage($image, $greagwar_image, $class::getMaxWidth(), $class::getMaxHeight(), $quality);
if ($force_create_variants) { if ($force_create_variants) {
@ -57,18 +56,16 @@ abstract class Upload
* @param int $quality * @param int $quality
* TODO: Сделать возможность передавать параметры для метода _resize() * TODO: Сделать возможность передавать параметры для метода _resize()
*/ */
public static function saveImage($image, $greagwar_image, $width = null, $height = null, $quality = 87)
public static function saveImage($image, $greagwar_image, $width = null, $height = null, $quality = 95)
{ {
if (!ImageVariant::getIsClass($image) && is_null($width) && is_null($height)) {
if (Image::getIsSubClass($image)) {
$width = $image::getMaxWidth();
$height = $image::getMaxHeight();
}
}
$greagwar_image = clone($greagwar_image); $greagwar_image = clone($greagwar_image);
if ($width || $height) { if ($width || $height) {
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 = true, $rescale = true, $crop = false); $greagwar_image->resize($width, $height, 0xffffff, $force = true, $rescale = true, $crop = false);
} }
}
$image->type = $greagwar_image->guessType(); $image->type = $greagwar_image->guessType();
$file_path = $greagwar_image->cacheFile($image->type, $quality, true); $file_path = $greagwar_image->cacheFile($image->type, $quality, true);
$image->size = filesize($file_path); $image->size = filesize($file_path);

Loading…
Cancel
Save