diff src/http/modules/ngx_http_image_filter_module.c @ 492:98143f74eb3d NGINX_0_7_58

nginx 0.7.58 *) Feature: a "listen" directive of the mail proxy module supports IPv6. *) Feature: the "image_filter_jpeg_quality" directive. *) Feature: the "client_body_in_single_buffer" directive. *) Feature: the $request_body variable. *) Bugfix: in ngx_http_autoindex_module in file name links having a ":" symbol in the name. *) Bugfix: "make upgrade" procedure did not work; the bug had appeared in 0.7.53. Thanks to Denis F. Latypoff.
author Igor Sysoev <http://sysoev.ru>
date Mon, 18 May 2009 00:00:00 +0400
parents e66f886a8305
children 499474178a11
line wrap: on
line diff
--- a/src/http/modules/ngx_http_image_filter_module.c
+++ b/src/http/modules/ngx_http_image_filter_module.c
@@ -38,6 +38,7 @@ typedef struct {
     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 @@ static ngx_command_t  ngx_http_image_fil
       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 @@ static u_char *
 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 @@ ngx_http_image_filter_create_conf(ngx_co
     }
 
     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 @@ ngx_http_image_filter_merge_conf(ngx_con
         }
     }
 
+    /* 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);