Nginx-ru mailing list archive (nginx-ru@sysoev.ru)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Качаство изображен ий после image_filter
On Sat, May 16, 2009 at 09:56:11PM +0600, Diem wrote:
> Здравствуйте Игорь.
> Нельзя ли включить опцию качества jpeg изображений в
> ngx_http_image_filter_module ?
> Дефолтное значение вполне приемливо, но не для фото маленьких размеров.
> В аттаче пример, где явно видны артефакты, для многих ситуаций - это
> просто недопустимо.
Патч.
image_filter_jpeg_quality [0-100]; # 75 is default
--
Игорь Сысоев
http://sysoev.ru
Index: src/http/modules/ngx_http_image_filter_module.c
===================================================================
--- src/http/modules/ngx_http_image_filter_module.c (revision 2167)
+++ src/http/modules/ngx_http_image_filter_module.c (working copy)
@@ -38,6 +38,7 @@
ngx_uint_t filter;
ngx_uint_t width;
ngx_uint_t height;
+ ngx_int_t jpeg_quality;
size_t buffer_size;
} ngx_http_image_filter_conf_t;
@@ -98,6 +99,13 @@
0,
NULL },
+ { ngx_string("image_filter_jpeg_quality"),
+ NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ NGX_HTTP_LOC_CONF_OFFSET,
+ offsetof(ngx_http_image_filter_conf_t, jpeg_quality),
+ NULL },
+
{ ngx_string("image_filter_buffer"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
ngx_conf_set_size_slot,
@@ -886,15 +894,17 @@
ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
int *size)
{
- char *failed;
- u_char *out;
+ char *failed;
+ u_char *out;
+ ngx_http_image_filter_conf_t *conf;
out = NULL;
switch (type) {
case NGX_HTTP_IMAGE_JPEG:
- out = gdImageJpegPtr(img, size, /* default quality */ -1);
+ conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
+ out = gdImageJpegPtr(img, size, conf->jpeg_quality);
failed = "gdImageJpegPtr() failed";
break;
@@ -939,6 +949,7 @@
}
conf->filter = NGX_CONF_UNSET_UINT;
+ conf->jpeg_quality = NGX_CONF_UNSET;
conf->buffer_size = NGX_CONF_UNSET_SIZE;
return conf;
@@ -963,6 +974,9 @@
}
}
+ /* 75 is libjpeg default quality */
+ ngx_conf_merge_value(conf->jpeg_quality, prev->jpeg_quality, 75);
+
ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
1 * 1024 * 1024);
|