Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_image_filter_module.c @ 8546:d80365ca678d quic
HTTP/3: require mandatory uni streams before additional ones.
As per quic-http-34:
Endpoints SHOULD create the HTTP control stream as well as the
unidirectional streams required by mandatory extensions (such as the
QPACK encoder and decoder streams) first, and then create additional
streams as allowed by their peer.
Previously, client could create and destroy additional uni streams unlimited
number of times before creating mandatory streams.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 29 Jul 2021 10:03:36 +0300 |
parents | 99934aade555 |
children |
rev | line source |
---|---|
2788 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
2788 | 5 */ |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
11 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
12 #include <gd.h> |
2788 | 13 |
14 | |
15 #define NGX_HTTP_IMAGE_OFF 0 | |
16 #define NGX_HTTP_IMAGE_TEST 1 | |
17 #define NGX_HTTP_IMAGE_SIZE 2 | |
18 #define NGX_HTTP_IMAGE_RESIZE 3 | |
19 #define NGX_HTTP_IMAGE_CROP 4 | |
3878 | 20 #define NGX_HTTP_IMAGE_ROTATE 5 |
2788 | 21 |
22 | |
23 #define NGX_HTTP_IMAGE_START 0 | |
24 #define NGX_HTTP_IMAGE_READ 1 | |
25 #define NGX_HTTP_IMAGE_PROCESS 2 | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
26 #define NGX_HTTP_IMAGE_PASS 3 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
27 #define NGX_HTTP_IMAGE_DONE 4 |
2788 | 28 |
29 | |
30 #define NGX_HTTP_IMAGE_NONE 0 | |
31 #define NGX_HTTP_IMAGE_JPEG 1 | |
32 #define NGX_HTTP_IMAGE_GIF 2 | |
33 #define NGX_HTTP_IMAGE_PNG 3 | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
34 #define NGX_HTTP_IMAGE_WEBP 4 |
2788 | 35 |
36 | |
37 #define NGX_HTTP_IMAGE_BUFFERED 0x08 | |
38 | |
39 | |
40 typedef struct { | |
41 ngx_uint_t filter; | |
42 ngx_uint_t width; | |
43 ngx_uint_t height; | |
3878 | 44 ngx_uint_t angle; |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
45 ngx_uint_t jpeg_quality; |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
46 ngx_uint_t webp_quality; |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
47 ngx_uint_t sharpen; |
2788 | 48 |
3134 | 49 ngx_flag_t transparency; |
5118
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
50 ngx_flag_t interlace; |
3134 | 51 |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
52 ngx_http_complex_value_t *wcv; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
53 ngx_http_complex_value_t *hcv; |
3878 | 54 ngx_http_complex_value_t *acv; |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
55 ngx_http_complex_value_t *jqcv; |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
56 ngx_http_complex_value_t *wqcv; |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
57 ngx_http_complex_value_t *shcv; |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
58 |
2788 | 59 size_t buffer_size; |
60 } ngx_http_image_filter_conf_t; | |
61 | |
62 | |
63 typedef struct { | |
64 u_char *image; | |
65 u_char *last; | |
66 | |
67 size_t length; | |
68 | |
69 ngx_uint_t width; | |
70 ngx_uint_t height; | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
71 ngx_uint_t max_width; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
72 ngx_uint_t max_height; |
3878 | 73 ngx_uint_t angle; |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
74 |
2788 | 75 ngx_uint_t phase; |
76 ngx_uint_t type; | |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
77 ngx_uint_t force; |
2788 | 78 } ngx_http_image_filter_ctx_t; |
79 | |
80 | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
81 static ngx_int_t ngx_http_image_send(ngx_http_request_t *r, |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
82 ngx_http_image_filter_ctx_t *ctx, ngx_chain_t *in); |
2788 | 83 static ngx_uint_t ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in); |
84 static ngx_int_t ngx_http_image_read(ngx_http_request_t *r, ngx_chain_t *in); | |
85 static ngx_buf_t *ngx_http_image_process(ngx_http_request_t *r); | |
86 static ngx_buf_t *ngx_http_image_json(ngx_http_request_t *r, | |
87 ngx_http_image_filter_ctx_t *ctx); | |
88 static ngx_buf_t *ngx_http_image_asis(ngx_http_request_t *r, | |
89 ngx_http_image_filter_ctx_t *ctx); | |
90 static void ngx_http_image_length(ngx_http_request_t *r, ngx_buf_t *b); | |
91 static ngx_int_t ngx_http_image_size(ngx_http_request_t *r, | |
92 ngx_http_image_filter_ctx_t *ctx); | |
93 | |
94 static ngx_buf_t *ngx_http_image_resize(ngx_http_request_t *r, | |
95 ngx_http_image_filter_ctx_t *ctx); | |
96 static gdImagePtr ngx_http_image_source(ngx_http_request_t *r, | |
97 ngx_http_image_filter_ctx_t *ctx); | |
98 static gdImagePtr ngx_http_image_new(ngx_http_request_t *r, int w, int h, | |
99 int colors); | |
100 static u_char *ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, | |
101 gdImagePtr img, int *size); | |
102 static void ngx_http_image_cleanup(void *data); | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
103 static ngx_uint_t ngx_http_image_filter_get_value(ngx_http_request_t *r, |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
104 ngx_http_complex_value_t *cv, ngx_uint_t v); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
105 static ngx_uint_t ngx_http_image_filter_value(ngx_str_t *value); |
2788 | 106 |
107 | |
108 static void *ngx_http_image_filter_create_conf(ngx_conf_t *cf); | |
109 static char *ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent, | |
110 void *child); | |
111 static char *ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd, | |
112 void *conf); | |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
113 static char *ngx_http_image_filter_jpeg_quality(ngx_conf_t *cf, |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
114 ngx_command_t *cmd, void *conf); |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
115 static char *ngx_http_image_filter_webp_quality(ngx_conf_t *cf, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
116 ngx_command_t *cmd, void *conf); |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
117 static char *ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd, |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
118 void *conf); |
2788 | 119 static ngx_int_t ngx_http_image_filter_init(ngx_conf_t *cf); |
120 | |
121 | |
122 static ngx_command_t ngx_http_image_filter_commands[] = { | |
123 | |
124 { ngx_string("image_filter"), | |
4307 | 125 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123, |
2788 | 126 ngx_http_image_filter, |
127 NGX_HTTP_LOC_CONF_OFFSET, | |
128 0, | |
129 NULL }, | |
130 | |
2848 | 131 { ngx_string("image_filter_jpeg_quality"), |
132 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
133 ngx_http_image_filter_jpeg_quality, |
2848 | 134 NGX_HTTP_LOC_CONF_OFFSET, |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
135 0, |
2848 | 136 NULL }, |
137 | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
138 { ngx_string("image_filter_webp_quality"), |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
139 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
140 ngx_http_image_filter_webp_quality, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
141 NGX_HTTP_LOC_CONF_OFFSET, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
142 0, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
143 NULL }, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
144 |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
145 { ngx_string("image_filter_sharpen"), |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
146 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
147 ngx_http_image_filter_sharpen, |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
148 NGX_HTTP_LOC_CONF_OFFSET, |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
149 0, |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
150 NULL }, |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
151 |
3134 | 152 { ngx_string("image_filter_transparency"), |
153 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
154 ngx_conf_set_flag_slot, | |
155 NGX_HTTP_LOC_CONF_OFFSET, | |
156 offsetof(ngx_http_image_filter_conf_t, transparency), | |
157 NULL }, | |
158 | |
6474 | 159 { ngx_string("image_filter_interlace"), |
5118
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
160 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
161 ngx_conf_set_flag_slot, |
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
162 NGX_HTTP_LOC_CONF_OFFSET, |
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
163 offsetof(ngx_http_image_filter_conf_t, interlace), |
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
164 NULL }, |
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
165 |
2788 | 166 { ngx_string("image_filter_buffer"), |
167 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
168 ngx_conf_set_size_slot, | |
169 NGX_HTTP_LOC_CONF_OFFSET, | |
170 offsetof(ngx_http_image_filter_conf_t, buffer_size), | |
171 NULL }, | |
172 | |
173 ngx_null_command | |
174 }; | |
175 | |
176 | |
177 static ngx_http_module_t ngx_http_image_filter_module_ctx = { | |
178 NULL, /* preconfiguration */ | |
179 ngx_http_image_filter_init, /* postconfiguration */ | |
180 | |
181 NULL, /* create main configuration */ | |
182 NULL, /* init main configuration */ | |
183 | |
184 NULL, /* create server configuration */ | |
185 NULL, /* merge server configuration */ | |
186 | |
187 ngx_http_image_filter_create_conf, /* create location configuration */ | |
188 ngx_http_image_filter_merge_conf /* merge location configuration */ | |
189 }; | |
190 | |
191 | |
192 ngx_module_t ngx_http_image_filter_module = { | |
193 NGX_MODULE_V1, | |
194 &ngx_http_image_filter_module_ctx, /* module context */ | |
195 ngx_http_image_filter_commands, /* module directives */ | |
196 NGX_HTTP_MODULE, /* module type */ | |
197 NULL, /* init master */ | |
198 NULL, /* init module */ | |
199 NULL, /* init process */ | |
200 NULL, /* init thread */ | |
201 NULL, /* exit thread */ | |
202 NULL, /* exit process */ | |
203 NULL, /* exit master */ | |
204 NGX_MODULE_V1_PADDING | |
205 }; | |
206 | |
207 | |
208 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | |
209 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | |
210 | |
211 | |
212 static ngx_str_t ngx_http_image_types[] = { | |
213 ngx_string("image/jpeg"), | |
214 ngx_string("image/gif"), | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
215 ngx_string("image/png"), |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
216 ngx_string("image/webp") |
2788 | 217 }; |
218 | |
219 | |
220 static ngx_int_t | |
221 ngx_http_image_header_filter(ngx_http_request_t *r) | |
222 { | |
223 off_t len; | |
224 ngx_http_image_filter_ctx_t *ctx; | |
225 ngx_http_image_filter_conf_t *conf; | |
226 | |
227 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) { | |
228 return ngx_http_next_header_filter(r); | |
229 } | |
230 | |
2834
0449d289256c
test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
231 ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module); |
0449d289256c
test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
232 |
0449d289256c
test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
233 if (ctx) { |
0449d289256c
test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
234 ngx_http_set_ctx(r, NULL, ngx_http_image_filter_module); |
0449d289256c
test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
235 return ngx_http_next_header_filter(r); |
0449d289256c
test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
236 } |
0449d289256c
test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents:
2821
diff
changeset
|
237 |
2788 | 238 conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module); |
239 | |
240 if (conf->filter == NGX_HTTP_IMAGE_OFF) { | |
241 return ngx_http_next_header_filter(r); | |
242 } | |
243 | |
244 if (r->headers_out.content_type.len | |
245 >= sizeof("multipart/x-mixed-replace") - 1 | |
246 && ngx_strncasecmp(r->headers_out.content_type.data, | |
247 (u_char *) "multipart/x-mixed-replace", | |
248 sizeof("multipart/x-mixed-replace") - 1) | |
249 == 0) | |
250 { | |
251 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
252 "image filter: multipart/x-mixed-replace response"); | |
253 | |
254 return NGX_ERROR; | |
255 } | |
256 | |
257 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_image_filter_ctx_t)); | |
258 if (ctx == NULL) { | |
259 return NGX_ERROR; | |
260 } | |
261 | |
262 ngx_http_set_ctx(r, ctx, ngx_http_image_filter_module); | |
263 | |
264 len = r->headers_out.content_length_n; | |
265 | |
2795
d82d08314f78
fix building ngx_http_image_filter_module on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents:
2788
diff
changeset
|
266 if (len != -1 && len > (off_t) conf->buffer_size) { |
2788 | 267 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
268 "image filter: too big response: %O", len); | |
269 | |
3722
1a728cc43bb1
return 415 on too big image in image filter
Igor Sysoev <igor@sysoev.ru>
parents:
3516
diff
changeset
|
270 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE; |
2788 | 271 } |
272 | |
273 if (len == -1) { | |
274 ctx->length = conf->buffer_size; | |
275 | |
276 } else { | |
277 ctx->length = (size_t) len; | |
278 } | |
279 | |
280 if (r->headers_out.refresh) { | |
281 r->headers_out.refresh->hash = 0; | |
282 } | |
283 | |
284 r->main_filter_need_in_memory = 1; | |
285 r->allow_ranges = 0; | |
286 | |
287 return NGX_OK; | |
288 } | |
289 | |
290 | |
291 static ngx_int_t | |
292 ngx_http_image_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
293 { | |
294 ngx_int_t rc; | |
295 ngx_str_t *ct; | |
296 ngx_chain_t out; | |
297 ngx_http_image_filter_ctx_t *ctx; | |
298 ngx_http_image_filter_conf_t *conf; | |
299 | |
300 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "image filter"); | |
301 | |
302 if (in == NULL) { | |
303 return ngx_http_next_body_filter(r, in); | |
304 } | |
305 | |
306 ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module); | |
307 | |
308 if (ctx == NULL) { | |
309 return ngx_http_next_body_filter(r, in); | |
310 } | |
311 | |
312 switch (ctx->phase) { | |
313 | |
314 case NGX_HTTP_IMAGE_START: | |
315 | |
316 ctx->type = ngx_http_image_test(r, in); | |
317 | |
318 conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module); | |
319 | |
320 if (ctx->type == NGX_HTTP_IMAGE_NONE) { | |
321 | |
322 if (conf->filter == NGX_HTTP_IMAGE_SIZE) { | |
323 out.buf = ngx_http_image_json(r, NULL); | |
324 | |
325 if (out.buf) { | |
326 out.next = NULL; | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
327 ctx->phase = NGX_HTTP_IMAGE_DONE; |
2788 | 328 |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
329 return ngx_http_image_send(r, ctx, &out); |
2788 | 330 } |
331 } | |
332 | |
333 return ngx_http_filter_finalize_request(r, | |
2821
26e06e009ced
allow to pass image filter errors via the same location where the filter is set
Igor Sysoev <igor@sysoev.ru>
parents:
2819
diff
changeset
|
334 &ngx_http_image_filter_module, |
2788 | 335 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE); |
336 } | |
337 | |
338 /* override content type */ | |
339 | |
340 ct = &ngx_http_image_types[ctx->type - 1]; | |
341 r->headers_out.content_type_len = ct->len; | |
342 r->headers_out.content_type = *ct; | |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2848
diff
changeset
|
343 r->headers_out.content_type_lowcase = NULL; |
2788 | 344 |
345 if (conf->filter == NGX_HTTP_IMAGE_TEST) { | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
346 ctx->phase = NGX_HTTP_IMAGE_PASS; |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
347 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
348 return ngx_http_image_send(r, ctx, in); |
2788 | 349 } |
350 | |
351 ctx->phase = NGX_HTTP_IMAGE_READ; | |
352 | |
353 /* fall through */ | |
354 | |
355 case NGX_HTTP_IMAGE_READ: | |
356 | |
357 rc = ngx_http_image_read(r, in); | |
358 | |
359 if (rc == NGX_AGAIN) { | |
360 return NGX_OK; | |
361 } | |
362 | |
363 if (rc == NGX_ERROR) { | |
364 return ngx_http_filter_finalize_request(r, | |
2821
26e06e009ced
allow to pass image filter errors via the same location where the filter is set
Igor Sysoev <igor@sysoev.ru>
parents:
2819
diff
changeset
|
365 &ngx_http_image_filter_module, |
2788 | 366 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE); |
367 } | |
368 | |
369 /* fall through */ | |
370 | |
371 case NGX_HTTP_IMAGE_PROCESS: | |
372 | |
373 out.buf = ngx_http_image_process(r); | |
374 | |
375 if (out.buf == NULL) { | |
376 return ngx_http_filter_finalize_request(r, | |
2821
26e06e009ced
allow to pass image filter errors via the same location where the filter is set
Igor Sysoev <igor@sysoev.ru>
parents:
2819
diff
changeset
|
377 &ngx_http_image_filter_module, |
2788 | 378 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE); |
379 } | |
380 | |
381 out.next = NULL; | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
382 ctx->phase = NGX_HTTP_IMAGE_PASS; |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
383 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
384 return ngx_http_image_send(r, ctx, &out); |
2788 | 385 |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
386 case NGX_HTTP_IMAGE_PASS: |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
387 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
388 return ngx_http_next_body_filter(r, in); |
2788 | 389 |
390 default: /* NGX_HTTP_IMAGE_DONE */ | |
391 | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
392 rc = ngx_http_next_body_filter(r, NULL); |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
393 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
394 /* NGX_ERROR resets any pending data */ |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
395 return (rc == NGX_OK) ? NGX_ERROR : rc; |
2788 | 396 } |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
397 } |
2788 | 398 |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
399 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
400 static ngx_int_t |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
401 ngx_http_image_send(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx, |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
402 ngx_chain_t *in) |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
403 { |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
404 ngx_int_t rc; |
2788 | 405 |
406 rc = ngx_http_next_header_filter(r); | |
407 | |
408 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
409 return NGX_ERROR; |
2788 | 410 } |
411 | |
2819
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
412 rc = ngx_http_next_body_filter(r, in); |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
413 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
414 if (ctx->phase == NGX_HTTP_IMAGE_DONE) { |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
415 /* NGX_ERROR resets any pending data */ |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
416 return (rc == NGX_OK) ? NGX_ERROR : rc; |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
417 } |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
418 |
43fe53832da7
handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents:
2795
diff
changeset
|
419 return rc; |
2788 | 420 } |
421 | |
422 | |
423 static ngx_uint_t | |
424 ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in) | |
425 { | |
426 u_char *p; | |
427 | |
428 p = in->buf->pos; | |
429 | |
430 if (in->buf->last - p < 16) { | |
431 return NGX_HTTP_IMAGE_NONE; | |
432 } | |
433 | |
434 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
435 "image filter: \"%c%c\"", p[0], p[1]); | |
436 | |
437 if (p[0] == 0xff && p[1] == 0xd8) { | |
438 | |
439 /* JPEG */ | |
440 | |
441 return NGX_HTTP_IMAGE_JPEG; | |
442 | |
443 } else if (p[0] == 'G' && p[1] == 'I' && p[2] == 'F' && p[3] == '8' | |
2918 | 444 && p[5] == 'a') |
2788 | 445 { |
2918 | 446 if (p[4] == '9' || p[4] == '7') { |
447 /* GIF */ | |
448 return NGX_HTTP_IMAGE_GIF; | |
449 } | |
2788 | 450 |
451 } else if (p[0] == 0x89 && p[1] == 'P' && p[2] == 'N' && p[3] == 'G' | |
452 && p[4] == 0x0d && p[5] == 0x0a && p[6] == 0x1a && p[7] == 0x0a) | |
453 { | |
454 /* PNG */ | |
455 | |
456 return NGX_HTTP_IMAGE_PNG; | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
457 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
458 } else if (p[0] == 'R' && p[1] == 'I' && p[2] == 'F' && p[3] == 'F' |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
459 && p[8] == 'W' && p[9] == 'E' && p[10] == 'B' && p[11] == 'P') |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
460 { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
461 /* WebP */ |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
462 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
463 return NGX_HTTP_IMAGE_WEBP; |
2788 | 464 } |
465 | |
466 return NGX_HTTP_IMAGE_NONE; | |
467 } | |
468 | |
469 | |
470 static ngx_int_t | |
471 ngx_http_image_read(ngx_http_request_t *r, ngx_chain_t *in) | |
472 { | |
473 u_char *p; | |
474 size_t size, rest; | |
475 ngx_buf_t *b; | |
476 ngx_chain_t *cl; | |
477 ngx_http_image_filter_ctx_t *ctx; | |
478 | |
479 ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module); | |
480 | |
481 if (ctx->image == NULL) { | |
482 ctx->image = ngx_palloc(r->pool, ctx->length); | |
483 if (ctx->image == NULL) { | |
484 return NGX_ERROR; | |
485 } | |
486 | |
487 ctx->last = ctx->image; | |
488 } | |
489 | |
490 p = ctx->last; | |
491 | |
492 for (cl = in; cl; cl = cl->next) { | |
493 | |
494 b = cl->buf; | |
495 size = b->last - b->pos; | |
496 | |
497 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
498 "image buf: %uz", size); | |
499 | |
500 rest = ctx->image + ctx->length - p; | |
5348
317e0893a1e6
Image filter: large image handling.
Lanshun Zhou <zls.sogou@gmail.com>
parents:
5315
diff
changeset
|
501 |
317e0893a1e6
Image filter: large image handling.
Lanshun Zhou <zls.sogou@gmail.com>
parents:
5315
diff
changeset
|
502 if (size > rest) { |
317e0893a1e6
Image filter: large image handling.
Lanshun Zhou <zls.sogou@gmail.com>
parents:
5315
diff
changeset
|
503 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
317e0893a1e6
Image filter: large image handling.
Lanshun Zhou <zls.sogou@gmail.com>
parents:
5315
diff
changeset
|
504 "image filter: too big response"); |
317e0893a1e6
Image filter: large image handling.
Lanshun Zhou <zls.sogou@gmail.com>
parents:
5315
diff
changeset
|
505 return NGX_ERROR; |
317e0893a1e6
Image filter: large image handling.
Lanshun Zhou <zls.sogou@gmail.com>
parents:
5315
diff
changeset
|
506 } |
2788 | 507 |
508 p = ngx_cpymem(p, b->pos, size); | |
509 b->pos += size; | |
510 | |
511 if (b->last_buf) { | |
512 ctx->last = p; | |
513 return NGX_OK; | |
514 } | |
515 } | |
516 | |
517 ctx->last = p; | |
518 r->connection->buffered |= NGX_HTTP_IMAGE_BUFFERED; | |
519 | |
520 return NGX_AGAIN; | |
521 } | |
522 | |
523 | |
524 static ngx_buf_t * | |
525 ngx_http_image_process(ngx_http_request_t *r) | |
526 { | |
527 ngx_int_t rc; | |
528 ngx_http_image_filter_ctx_t *ctx; | |
529 ngx_http_image_filter_conf_t *conf; | |
530 | |
531 r->connection->buffered &= ~NGX_HTTP_IMAGE_BUFFERED; | |
532 | |
533 ctx = ngx_http_get_module_ctx(r, ngx_http_image_filter_module); | |
534 | |
535 rc = ngx_http_image_size(r, ctx); | |
536 | |
537 conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module); | |
538 | |
539 if (conf->filter == NGX_HTTP_IMAGE_SIZE) { | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
540 return ngx_http_image_json(r, rc == NGX_OK ? ctx : NULL); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
541 } |
2788 | 542 |
3878 | 543 ctx->angle = ngx_http_image_filter_get_value(r, conf->acv, conf->angle); |
544 | |
545 if (conf->filter == NGX_HTTP_IMAGE_ROTATE) { | |
546 | |
547 if (ctx->angle != 90 && ctx->angle != 180 && ctx->angle != 270) { | |
548 return NULL; | |
549 } | |
550 | |
551 return ngx_http_image_resize(r, ctx); | |
552 } | |
553 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
554 ctx->max_width = ngx_http_image_filter_get_value(r, conf->wcv, conf->width); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
555 if (ctx->max_width == 0) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
556 return NULL; |
2788 | 557 } |
558 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
559 ctx->max_height = ngx_http_image_filter_get_value(r, conf->hcv, |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
560 conf->height); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
561 if (ctx->max_height == 0) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
562 return NULL; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
563 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
564 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
565 if (rc == NGX_OK |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
566 && ctx->width <= ctx->max_width |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
567 && ctx->height <= ctx->max_height |
3878 | 568 && ctx->angle == 0 |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
569 && !ctx->force) |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
570 { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
571 return ngx_http_image_asis(r, ctx); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
572 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
573 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
574 return ngx_http_image_resize(r, ctx); |
2788 | 575 } |
576 | |
577 | |
578 static ngx_buf_t * | |
579 ngx_http_image_json(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) | |
580 { | |
581 size_t len; | |
582 ngx_buf_t *b; | |
583 | |
6973
99934aade555
Use ngx_calloc_buf() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6779
diff
changeset
|
584 b = ngx_calloc_buf(r->pool); |
2788 | 585 if (b == NULL) { |
586 return NULL; | |
587 } | |
588 | |
589 b->memory = 1; | |
590 b->last_buf = 1; | |
591 | |
592 ngx_http_clean_header(r); | |
593 | |
594 r->headers_out.status = NGX_HTTP_OK; | |
5497
2cfc095a607a
Fixed setting of content type in some cases.
Ruslan Ermilov <ru@nginx.com>
parents:
5348
diff
changeset
|
595 r->headers_out.content_type_len = sizeof("application/json") - 1; |
5315
31932b5464f0
Image filter: use "application/json" MIME type for JSON output.
Valentin Bartenev <vbart@nginx.com>
parents:
5118
diff
changeset
|
596 ngx_str_set(&r->headers_out.content_type, "application/json"); |
2882
896db5a09bd2
reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents:
2848
diff
changeset
|
597 r->headers_out.content_type_lowcase = NULL; |
2788 | 598 |
599 if (ctx == NULL) { | |
600 b->pos = (u_char *) "{}" CRLF; | |
601 b->last = b->pos + sizeof("{}" CRLF) - 1; | |
602 | |
603 ngx_http_image_length(r, b); | |
604 | |
605 return b; | |
606 } | |
607 | |
608 len = sizeof("{ \"img\" : " | |
609 "{ \"width\": , \"height\": , \"type\": \"jpeg\" } }" CRLF) - 1 | |
610 + 2 * NGX_SIZE_T_LEN; | |
611 | |
612 b->pos = ngx_pnalloc(r->pool, len); | |
613 if (b->pos == NULL) { | |
614 return NULL; | |
615 } | |
616 | |
617 b->last = ngx_sprintf(b->pos, | |
618 "{ \"img\" : " | |
619 "{ \"width\": %uz," | |
620 " \"height\": %uz," | |
621 " \"type\": \"%s\" } }" CRLF, | |
622 ctx->width, ctx->height, | |
623 ngx_http_image_types[ctx->type - 1].data + 6); | |
624 | |
625 ngx_http_image_length(r, b); | |
626 | |
627 return b; | |
628 } | |
629 | |
630 | |
631 static ngx_buf_t * | |
632 ngx_http_image_asis(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) | |
633 { | |
634 ngx_buf_t *b; | |
635 | |
6973
99934aade555
Use ngx_calloc_buf() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6779
diff
changeset
|
636 b = ngx_calloc_buf(r->pool); |
2788 | 637 if (b == NULL) { |
638 return NULL; | |
639 } | |
640 | |
641 b->pos = ctx->image; | |
642 b->last = ctx->last; | |
643 b->memory = 1; | |
644 b->last_buf = 1; | |
645 | |
646 ngx_http_image_length(r, b); | |
647 | |
648 return b; | |
649 } | |
650 | |
651 | |
652 static void | |
653 ngx_http_image_length(ngx_http_request_t *r, ngx_buf_t *b) | |
654 { | |
655 r->headers_out.content_length_n = b->last - b->pos; | |
656 | |
657 if (r->headers_out.content_length) { | |
658 r->headers_out.content_length->hash = 0; | |
659 } | |
660 | |
661 r->headers_out.content_length = NULL; | |
662 } | |
663 | |
664 | |
665 static ngx_int_t | |
666 ngx_http_image_size(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) | |
667 { | |
668 u_char *p, *last; | |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
669 size_t len, app; |
2788 | 670 ngx_uint_t width, height; |
671 | |
672 p = ctx->image; | |
673 | |
674 switch (ctx->type) { | |
675 | |
676 case NGX_HTTP_IMAGE_JPEG: | |
677 | |
678 p += 2; | |
679 last = ctx->image + ctx->length - 10; | |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
680 width = 0; |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
681 height = 0; |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
682 app = 0; |
2788 | 683 |
684 while (p < last) { | |
685 | |
686 if (p[0] == 0xff && p[1] != 0xff) { | |
687 | |
688 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
3393 | 689 "JPEG: %02xd %02xd", p[0], p[1]); |
2788 | 690 |
691 p++; | |
692 | |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
693 if ((*p == 0xc0 || *p == 0xc1 || *p == 0xc2 || *p == 0xc3 |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
694 || *p == 0xc9 || *p == 0xca || *p == 0xcb) |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
695 && (width == 0 || height == 0)) |
2788 | 696 { |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
697 width = p[6] * 256 + p[7]; |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
698 height = p[4] * 256 + p[5]; |
2788 | 699 } |
700 | |
701 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
702 "JPEG: %02xd %02xd", p[1], p[2]); | |
703 | |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
704 len = p[1] * 256 + p[2]; |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
705 |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
706 if (*p >= 0xe1 && *p <= 0xef) { |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
707 /* application data, e.g., EXIF, Adobe XMP, etc. */ |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
708 app += len; |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
709 } |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
710 |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
711 p += len; |
2788 | 712 |
713 continue; | |
714 } | |
715 | |
716 p++; | |
717 } | |
718 | |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
719 if (width == 0 || height == 0) { |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
720 return NGX_DECLINED; |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
721 } |
2788 | 722 |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
723 if (ctx->length / 20 < app) { |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
724 /* force conversion if application data consume more than 5% */ |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
725 ctx->force = 1; |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
726 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
727 "app data size: %uz", app); |
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
728 } |
2788 | 729 |
730 break; | |
731 | |
732 case NGX_HTTP_IMAGE_GIF: | |
733 | |
734 if (ctx->length < 10) { | |
735 return NGX_DECLINED; | |
736 } | |
737 | |
738 width = p[7] * 256 + p[6]; | |
739 height = p[9] * 256 + p[8]; | |
740 | |
741 break; | |
742 | |
743 case NGX_HTTP_IMAGE_PNG: | |
744 | |
745 if (ctx->length < 24) { | |
746 return NGX_DECLINED; | |
747 } | |
748 | |
749 width = p[18] * 256 + p[19]; | |
750 height = p[22] * 256 + p[23]; | |
751 | |
752 break; | |
753 | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
754 case NGX_HTTP_IMAGE_WEBP: |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
755 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
756 if (ctx->length < 30) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
757 return NGX_DECLINED; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
758 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
759 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
760 if (p[12] != 'V' || p[13] != 'P' || p[14] != '8') { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
761 return NGX_DECLINED; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
762 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
763 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
764 switch (p[15]) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
765 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
766 case ' ': |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
767 if (p[20] & 1) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
768 /* not a key frame */ |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
769 return NGX_DECLINED; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
770 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
771 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
772 if (p[23] != 0x9d || p[24] != 0x01 || p[25] != 0x2a) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
773 /* invalid start code */ |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
774 return NGX_DECLINED; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
775 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
776 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
777 width = (p[26] | p[27] << 8) & 0x3fff; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
778 height = (p[28] | p[29] << 8) & 0x3fff; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
779 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
780 break; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
781 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
782 case 'L': |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
783 if (p[20] != 0x2f) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
784 /* invalid signature */ |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
785 return NGX_DECLINED; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
786 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
787 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
788 width = ((p[21] | p[22] << 8) & 0x3fff) + 1; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
789 height = ((p[22] >> 6 | p[23] << 2 | p[24] << 10) & 0x3fff) + 1; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
790 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
791 break; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
792 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
793 case 'X': |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
794 width = (p[24] | p[25] << 8 | p[26] << 16) + 1; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
795 height = (p[27] | p[28] << 8 | p[29] << 16) + 1; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
796 break; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
797 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
798 default: |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
799 return NGX_DECLINED; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
800 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
801 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
802 break; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
803 |
2788 | 804 default: |
805 | |
806 return NGX_DECLINED; | |
807 } | |
808 | |
809 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
6480 | 810 "image size: %d x %d", (int) width, (int) height); |
2788 | 811 |
812 ctx->width = width; | |
813 ctx->height = height; | |
814 | |
815 return NGX_OK; | |
816 } | |
817 | |
818 | |
819 static ngx_buf_t * | |
820 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) | |
821 { | |
3910
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
822 int sx, sy, dx, dy, ox, oy, ax, ay, size, |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
823 colors, palette, transparent, sharpen, |
3878 | 824 red, green, blue, t; |
2788 | 825 u_char *out; |
826 ngx_buf_t *b; | |
827 ngx_uint_t resize; | |
828 gdImagePtr src, dst; | |
829 ngx_pool_cleanup_t *cln; | |
830 ngx_http_image_filter_conf_t *conf; | |
831 | |
832 src = ngx_http_image_source(r, ctx); | |
833 | |
834 if (src == NULL) { | |
835 return NULL; | |
836 } | |
837 | |
838 sx = gdImageSX(src); | |
839 sy = gdImageSY(src); | |
840 | |
841 conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module); | |
842 | |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
843 if (!ctx->force |
3878 | 844 && ctx->angle == 0 |
3394
11965c62b92c
force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents:
3393
diff
changeset
|
845 && (ngx_uint_t) sx <= ctx->max_width |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
846 && (ngx_uint_t) sy <= ctx->max_height) |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
847 { |
2788 | 848 gdImageDestroy(src); |
849 return ngx_http_image_asis(r, ctx); | |
850 } | |
851 | |
852 colors = gdImageColorsTotal(src); | |
3134 | 853 |
854 if (colors && conf->transparency) { | |
855 transparent = gdImageGetTransparent(src); | |
856 | |
857 if (transparent != -1) { | |
858 palette = colors; | |
859 red = gdImageRed(src, transparent); | |
860 green = gdImageGreen(src, transparent); | |
861 blue = gdImageBlue(src, transparent); | |
2788 | 862 |
3134 | 863 goto transparent; |
864 } | |
865 } | |
3117 | 866 |
3134 | 867 palette = 0; |
868 transparent = -1; | |
869 red = 0; | |
870 green = 0; | |
871 blue = 0; | |
872 | |
873 transparent: | |
874 | |
875 gdImageColorTransparent(src, -1); | |
3117 | 876 |
2788 | 877 dx = sx; |
878 dy = sy; | |
879 | |
880 if (conf->filter == NGX_HTTP_IMAGE_RESIZE) { | |
881 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
882 if ((ngx_uint_t) dx > ctx->max_width) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
883 dy = dy * ctx->max_width / dx; |
2788 | 884 dy = dy ? dy : 1; |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
885 dx = ctx->max_width; |
2788 | 886 } |
887 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
888 if ((ngx_uint_t) dy > ctx->max_height) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
889 dx = dx * ctx->max_height / dy; |
2788 | 890 dx = dx ? dx : 1; |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
891 dy = ctx->max_height; |
2788 | 892 } |
893 | |
894 resize = 1; | |
895 | |
3878 | 896 } else if (conf->filter == NGX_HTTP_IMAGE_ROTATE) { |
897 | |
898 resize = 0; | |
899 | |
2788 | 900 } else { /* NGX_HTTP_IMAGE_CROP */ |
901 | |
902 resize = 0; | |
903 | |
4601
084137d883ec
Image filter: compare aspect ratio more accurately during crop.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
904 if ((double) dx / dy < (double) ctx->max_width / ctx->max_height) { |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
905 if ((ngx_uint_t) dx > ctx->max_width) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
906 dy = dy * ctx->max_width / dx; |
2788 | 907 dy = dy ? dy : 1; |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
908 dx = ctx->max_width; |
2788 | 909 resize = 1; |
910 } | |
911 | |
912 } else { | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
913 if ((ngx_uint_t) dy > ctx->max_height) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
914 dx = dx * ctx->max_height / dy; |
2788 | 915 dx = dx ? dx : 1; |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
916 dy = ctx->max_height; |
2788 | 917 resize = 1; |
918 } | |
919 } | |
920 } | |
921 | |
922 if (resize) { | |
3134 | 923 dst = ngx_http_image_new(r, dx, dy, palette); |
2788 | 924 if (dst == NULL) { |
925 gdImageDestroy(src); | |
926 return NULL; | |
927 } | |
928 | |
3133
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
929 if (colors == 0) { |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
930 gdImageSaveAlpha(dst, 1); |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
931 gdImageAlphaBlending(dst, 0); |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
932 } |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
933 |
2788 | 934 gdImageCopyResampled(dst, src, 0, 0, 0, 0, dx, dy, sx, sy); |
935 | |
3134 | 936 if (colors) { |
937 gdImageTrueColorToPalette(dst, 1, 256); | |
938 } | |
939 | |
2788 | 940 gdImageDestroy(src); |
941 | |
942 } else { | |
943 dst = src; | |
944 } | |
945 | |
3878 | 946 if (ctx->angle) { |
947 src = dst; | |
948 | |
3910
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
949 ax = (dx % 2 == 0) ? 1 : 0; |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
950 ay = (dy % 2 == 0) ? 1 : 0; |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
951 |
3878 | 952 switch (ctx->angle) { |
953 | |
954 case 90: | |
955 case 270: | |
956 dst = ngx_http_image_new(r, dy, dx, palette); | |
957 if (dst == NULL) { | |
958 gdImageDestroy(src); | |
959 return NULL; | |
960 } | |
3910
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
961 if (ctx->angle == 90) { |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
962 ox = dy / 2 + ay; |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
963 oy = dx / 2 - ax; |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
964 |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
965 } else { |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
966 ox = dy / 2 - ay; |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
967 oy = dx / 2 + ax; |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
968 } |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
969 |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
970 gdImageCopyRotated(dst, src, ox, oy, 0, 0, |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
971 dx + ax, dy + ay, ctx->angle); |
3878 | 972 gdImageDestroy(src); |
3884
ea712f4dc030
fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents:
3878
diff
changeset
|
973 |
ea712f4dc030
fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents:
3878
diff
changeset
|
974 t = dx; |
ea712f4dc030
fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents:
3878
diff
changeset
|
975 dx = dy; |
ea712f4dc030
fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents:
3878
diff
changeset
|
976 dy = t; |
3878 | 977 break; |
978 | |
979 case 180: | |
980 dst = ngx_http_image_new(r, dx, dy, palette); | |
981 if (dst == NULL) { | |
982 gdImageDestroy(src); | |
983 return NULL; | |
984 } | |
3910
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
985 gdImageCopyRotated(dst, src, dx / 2 - ax, dy / 2 - ay, 0, 0, |
750fb808aa15
gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents:
3884
diff
changeset
|
986 dx + ax, dy + ay, ctx->angle); |
3878 | 987 gdImageDestroy(src); |
988 break; | |
989 } | |
990 } | |
991 | |
2788 | 992 if (conf->filter == NGX_HTTP_IMAGE_CROP) { |
993 | |
994 src = dst; | |
995 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
996 if ((ngx_uint_t) dx > ctx->max_width) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
997 ox = dx - ctx->max_width; |
2788 | 998 |
999 } else { | |
1000 ox = 0; | |
1001 } | |
1002 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1003 if ((ngx_uint_t) dy > ctx->max_height) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1004 oy = dy - ctx->max_height; |
2788 | 1005 |
1006 } else { | |
1007 oy = 0; | |
1008 } | |
1009 | |
1010 if (ox || oy) { | |
1011 | |
1012 dst = ngx_http_image_new(r, dx - ox, dy - oy, colors); | |
1013 | |
1014 if (dst == NULL) { | |
1015 gdImageDestroy(src); | |
1016 return NULL; | |
1017 } | |
1018 | |
1019 ox /= 2; | |
1020 oy /= 2; | |
1021 | |
1022 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1023 "image crop: %d x %d @ %d x %d", | |
1024 dx, dy, ox, oy); | |
1025 | |
3133
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
1026 if (colors == 0) { |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
1027 gdImageSaveAlpha(dst, 1); |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
1028 gdImageAlphaBlending(dst, 0); |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
1029 } |
28a6aa24b453
fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents:
3117
diff
changeset
|
1030 |
2788 | 1031 gdImageCopy(dst, src, 0, 0, ox, oy, dx - ox, dy - oy); |
1032 | |
3134 | 1033 if (colors) { |
1034 gdImageTrueColorToPalette(dst, 1, 256); | |
1035 } | |
1036 | |
2788 | 1037 gdImageDestroy(src); |
1038 } | |
1039 } | |
1040 | |
3117 | 1041 if (transparent != -1 && colors) { |
1042 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue)); | |
1043 } | |
2788 | 1044 |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1045 sharpen = ngx_http_image_filter_get_value(r, conf->shcv, conf->sharpen); |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1046 if (sharpen > 0) { |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1047 gdImageSharpen(dst, sharpen); |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1048 } |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1049 |
5118
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
1050 gdImageInterlace(dst, (int) conf->interlace); |
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
1051 |
2788 | 1052 out = ngx_http_image_out(r, ctx->type, dst, &size); |
1053 | |
1054 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1055 "image: %d x %d %d", sx, sy, colors); | |
1056 | |
1057 gdImageDestroy(dst); | |
1058 ngx_pfree(r->pool, ctx->image); | |
1059 | |
1060 if (out == NULL) { | |
1061 return NULL; | |
1062 } | |
1063 | |
1064 cln = ngx_pool_cleanup_add(r->pool, 0); | |
1065 if (cln == NULL) { | |
1066 gdFree(out); | |
1067 return NULL; | |
1068 } | |
1069 | |
6973
99934aade555
Use ngx_calloc_buf() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6779
diff
changeset
|
1070 b = ngx_calloc_buf(r->pool); |
2788 | 1071 if (b == NULL) { |
1072 gdFree(out); | |
1073 return NULL; | |
1074 } | |
1075 | |
1076 cln->handler = ngx_http_image_cleanup; | |
1077 cln->data = out; | |
1078 | |
1079 b->pos = out; | |
1080 b->last = out + size; | |
1081 b->memory = 1; | |
1082 b->last_buf = 1; | |
1083 | |
1084 ngx_http_image_length(r, b); | |
5806
8cdec62a7751
Image filter: downgrade strong etags to weak ones as needed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5497
diff
changeset
|
1085 ngx_http_weak_etag(r); |
2788 | 1086 |
1087 return b; | |
1088 } | |
1089 | |
1090 | |
1091 static gdImagePtr | |
1092 ngx_http_image_source(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) | |
1093 { | |
1094 char *failed; | |
1095 gdImagePtr img; | |
1096 | |
1097 img = NULL; | |
1098 | |
1099 switch (ctx->type) { | |
1100 | |
1101 case NGX_HTTP_IMAGE_JPEG: | |
1102 img = gdImageCreateFromJpegPtr(ctx->length, ctx->image); | |
1103 failed = "gdImageCreateFromJpegPtr() failed"; | |
1104 break; | |
1105 | |
1106 case NGX_HTTP_IMAGE_GIF: | |
1107 img = gdImageCreateFromGifPtr(ctx->length, ctx->image); | |
1108 failed = "gdImageCreateFromGifPtr() failed"; | |
1109 break; | |
1110 | |
1111 case NGX_HTTP_IMAGE_PNG: | |
1112 img = gdImageCreateFromPngPtr(ctx->length, ctx->image); | |
1113 failed = "gdImageCreateFromPngPtr() failed"; | |
1114 break; | |
1115 | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1116 case NGX_HTTP_IMAGE_WEBP: |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1117 #if (NGX_HAVE_GD_WEBP) |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1118 img = gdImageCreateFromWebpPtr(ctx->length, ctx->image); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1119 failed = "gdImageCreateFromWebpPtr() failed"; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1120 #else |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1121 failed = "nginx was built without GD WebP support"; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1122 #endif |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1123 break; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1124 |
2788 | 1125 default: |
1126 failed = "unknown image type"; | |
1127 break; | |
1128 } | |
1129 | |
1130 if (img == NULL) { | |
1131 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, failed); | |
1132 } | |
1133 | |
1134 return img; | |
1135 } | |
1136 | |
1137 | |
1138 static gdImagePtr | |
1139 ngx_http_image_new(ngx_http_request_t *r, int w, int h, int colors) | |
1140 { | |
1141 gdImagePtr img; | |
1142 | |
1143 if (colors == 0) { | |
1144 img = gdImageCreateTrueColor(w, h); | |
1145 | |
1146 if (img == NULL) { | |
1147 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1148 "gdImageCreateTrueColor() failed"); | |
1149 return NULL; | |
1150 } | |
1151 | |
1152 } else { | |
1153 img = gdImageCreate(w, h); | |
1154 | |
1155 if (img == NULL) { | |
1156 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, | |
1157 "gdImageCreate() failed"); | |
1158 return NULL; | |
1159 } | |
1160 } | |
1161 | |
1162 return img; | |
1163 } | |
1164 | |
1165 | |
1166 static u_char * | |
1167 ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img, | |
1168 int *size) | |
1169 { | |
2848 | 1170 char *failed; |
1171 u_char *out; | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1172 ngx_int_t q; |
2848 | 1173 ngx_http_image_filter_conf_t *conf; |
2788 | 1174 |
1175 out = NULL; | |
1176 | |
1177 switch (type) { | |
1178 | |
1179 case NGX_HTTP_IMAGE_JPEG: | |
2848 | 1180 conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module); |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1181 |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1182 q = ngx_http_image_filter_get_value(r, conf->jqcv, conf->jpeg_quality); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1183 if (q <= 0) { |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1184 return NULL; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1185 } |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1186 |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1187 out = gdImageJpegPtr(img, size, q); |
2788 | 1188 failed = "gdImageJpegPtr() failed"; |
1189 break; | |
1190 | |
1191 case NGX_HTTP_IMAGE_GIF: | |
1192 out = gdImageGifPtr(img, size); | |
1193 failed = "gdImageGifPtr() failed"; | |
1194 break; | |
1195 | |
1196 case NGX_HTTP_IMAGE_PNG: | |
1197 out = gdImagePngPtr(img, size); | |
1198 failed = "gdImagePngPtr() failed"; | |
1199 break; | |
1200 | |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1201 case NGX_HTTP_IMAGE_WEBP: |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1202 #if (NGX_HAVE_GD_WEBP) |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1203 conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1204 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1205 q = ngx_http_image_filter_get_value(r, conf->wqcv, conf->webp_quality); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1206 if (q <= 0) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1207 return NULL; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1208 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1209 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1210 out = gdImageWebpPtrEx(img, size, q); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1211 failed = "gdImageWebpPtrEx() failed"; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1212 #else |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1213 failed = "nginx was built without GD WebP support"; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1214 #endif |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1215 break; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1216 |
2788 | 1217 default: |
1218 failed = "unknown image type"; | |
1219 break; | |
1220 } | |
1221 | |
1222 if (out == NULL) { | |
1223 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, failed); | |
1224 } | |
1225 | |
1226 return out; | |
1227 } | |
1228 | |
1229 | |
1230 static void | |
1231 ngx_http_image_cleanup(void *data) | |
1232 { | |
1233 gdFree(data); | |
1234 } | |
1235 | |
1236 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1237 static ngx_uint_t |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1238 ngx_http_image_filter_get_value(ngx_http_request_t *r, |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1239 ngx_http_complex_value_t *cv, ngx_uint_t v) |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1240 { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1241 ngx_str_t val; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1242 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1243 if (cv == NULL) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1244 return v; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1245 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1246 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1247 if (ngx_http_complex_value(r, cv, &val) != NGX_OK) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1248 return 0; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1249 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1250 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1251 return ngx_http_image_filter_value(&val); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1252 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1253 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1254 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1255 static ngx_uint_t |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1256 ngx_http_image_filter_value(ngx_str_t *value) |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1257 { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1258 ngx_int_t n; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1259 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1260 if (value->len == 1 && value->data[0] == '-') { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1261 return (ngx_uint_t) -1; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1262 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1263 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1264 n = ngx_atoi(value->data, value->len); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1265 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1266 if (n > 0) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1267 return (ngx_uint_t) n; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1268 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1269 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1270 return 0; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1271 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1272 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1273 |
2788 | 1274 static void * |
1275 ngx_http_image_filter_create_conf(ngx_conf_t *cf) | |
1276 { | |
1277 ngx_http_image_filter_conf_t *conf; | |
1278 | |
1279 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_image_filter_conf_t)); | |
1280 if (conf == NULL) { | |
2912
c7d57b539248
return NULL instead of NGX_CONF_ERROR on a create conf failure
Igor Sysoev <igor@sysoev.ru>
parents:
2882
diff
changeset
|
1281 return NULL; |
2788 | 1282 } |
1283 | |
4981
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1284 /* |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1285 * set by ngx_pcalloc(): |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1286 * |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1287 * conf->width = 0; |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1288 * conf->height = 0; |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1289 * conf->angle = 0; |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1290 * conf->wcv = NULL; |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1291 * conf->hcv = NULL; |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1292 * conf->acv = NULL; |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1293 * conf->jqcv = NULL; |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1294 * conf->wqcv = NULL; |
4981
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1295 * conf->shcv = NULL; |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1296 */ |
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1297 |
2788 | 1298 conf->filter = NGX_CONF_UNSET_UINT; |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1299 conf->jpeg_quality = NGX_CONF_UNSET_UINT; |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1300 conf->webp_quality = NGX_CONF_UNSET_UINT; |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1301 conf->sharpen = NGX_CONF_UNSET_UINT; |
3134 | 1302 conf->transparency = NGX_CONF_UNSET; |
5118
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
1303 conf->interlace = NGX_CONF_UNSET; |
2788 | 1304 conf->buffer_size = NGX_CONF_UNSET_SIZE; |
1305 | |
1306 return conf; | |
1307 } | |
1308 | |
1309 | |
1310 static char * | |
1311 ngx_http_image_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
1312 { | |
1313 ngx_http_image_filter_conf_t *prev = parent; | |
1314 ngx_http_image_filter_conf_t *conf = child; | |
1315 | |
1316 if (conf->filter == NGX_CONF_UNSET_UINT) { | |
1317 | |
1318 if (prev->filter == NGX_CONF_UNSET_UINT) { | |
1319 conf->filter = NGX_HTTP_IMAGE_OFF; | |
1320 | |
1321 } else { | |
1322 conf->filter = prev->filter; | |
1323 conf->width = prev->width; | |
1324 conf->height = prev->height; | |
4981
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1325 conf->angle = prev->angle; |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1326 conf->wcv = prev->wcv; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1327 conf->hcv = prev->hcv; |
4981
5889bc5f7a65
Image filter: fixed image_filter rotate inheritance.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4978
diff
changeset
|
1328 conf->acv = prev->acv; |
2788 | 1329 } |
1330 } | |
1331 | |
4978
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1332 if (conf->jpeg_quality == NGX_CONF_UNSET_UINT) { |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1333 |
4978
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1334 /* 75 is libjpeg default quality */ |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1335 ngx_conf_merge_uint_value(conf->jpeg_quality, prev->jpeg_quality, 75); |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1336 |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1337 if (conf->jqcv == NULL) { |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1338 conf->jqcv = prev->jqcv; |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1339 } |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1340 } |
2848 | 1341 |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1342 if (conf->webp_quality == NGX_CONF_UNSET_UINT) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1343 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1344 /* 80 is libwebp default quality */ |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1345 ngx_conf_merge_uint_value(conf->webp_quality, prev->webp_quality, 80); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1346 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1347 if (conf->wqcv == NULL) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1348 conf->wqcv = prev->wqcv; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1349 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1350 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1351 |
4978
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1352 if (conf->sharpen == NGX_CONF_UNSET_UINT) { |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1353 ngx_conf_merge_uint_value(conf->sharpen, prev->sharpen, 0); |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1354 |
4978
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1355 if (conf->shcv == NULL) { |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1356 conf->shcv = prev->shcv; |
55ccb9f75668
Image filter: configuration inheritance fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4601
diff
changeset
|
1357 } |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1358 } |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1359 |
3134 | 1360 ngx_conf_merge_value(conf->transparency, prev->transparency, 1); |
1361 | |
5118
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
1362 ngx_conf_merge_value(conf->interlace, prev->interlace, 0); |
af155fc41deb
Image filter: the "image_filter_interlace" directive.
Ruslan Ermilov <ru@nginx.com>
parents:
4981
diff
changeset
|
1363 |
2788 | 1364 ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, |
1365 1 * 1024 * 1024); | |
1366 | |
1367 return NGX_CONF_OK; | |
1368 } | |
1369 | |
1370 | |
1371 static char * | |
1372 ngx_http_image_filter(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
1373 { | |
1374 ngx_http_image_filter_conf_t *imcf = conf; | |
1375 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1376 ngx_str_t *value; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1377 ngx_int_t n; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1378 ngx_uint_t i; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1379 ngx_http_complex_value_t cv; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1380 ngx_http_compile_complex_value_t ccv; |
2788 | 1381 |
1382 value = cf->args->elts; | |
1383 | |
1384 i = 1; | |
1385 | |
1386 if (cf->args->nelts == 2) { | |
1387 if (ngx_strcmp(value[i].data, "off") == 0) { | |
1388 imcf->filter = NGX_HTTP_IMAGE_OFF; | |
1389 | |
1390 } else if (ngx_strcmp(value[i].data, "test") == 0) { | |
1391 imcf->filter = NGX_HTTP_IMAGE_TEST; | |
1392 | |
1393 } else if (ngx_strcmp(value[i].data, "size") == 0) { | |
1394 imcf->filter = NGX_HTTP_IMAGE_SIZE; | |
1395 | |
1396 } else { | |
1397 goto failed; | |
1398 } | |
1399 | |
1400 return NGX_CONF_OK; | |
3878 | 1401 |
1402 } else if (cf->args->nelts == 3) { | |
1403 | |
1404 if (ngx_strcmp(value[i].data, "rotate") == 0) { | |
4308
39982fa69482
Fixed "rotate" to always work when combined with "resize/crop".
Ruslan Ermilov <ru@nginx.com>
parents:
4307
diff
changeset
|
1405 if (imcf->filter != NGX_HTTP_IMAGE_RESIZE |
39982fa69482
Fixed "rotate" to always work when combined with "resize/crop".
Ruslan Ermilov <ru@nginx.com>
parents:
4307
diff
changeset
|
1406 && imcf->filter != NGX_HTTP_IMAGE_CROP) |
39982fa69482
Fixed "rotate" to always work when combined with "resize/crop".
Ruslan Ermilov <ru@nginx.com>
parents:
4307
diff
changeset
|
1407 { |
39982fa69482
Fixed "rotate" to always work when combined with "resize/crop".
Ruslan Ermilov <ru@nginx.com>
parents:
4307
diff
changeset
|
1408 imcf->filter = NGX_HTTP_IMAGE_ROTATE; |
39982fa69482
Fixed "rotate" to always work when combined with "resize/crop".
Ruslan Ermilov <ru@nginx.com>
parents:
4307
diff
changeset
|
1409 } |
3878 | 1410 |
1411 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
1412 | |
1413 ccv.cf = cf; | |
1414 ccv.value = &value[++i]; | |
1415 ccv.complex_value = &cv; | |
1416 | |
1417 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
1418 return NGX_CONF_ERROR; | |
1419 } | |
1420 | |
1421 if (cv.lengths == NULL) { | |
1422 n = ngx_http_image_filter_value(&value[i]); | |
1423 | |
1424 if (n != 90 && n != 180 && n != 270) { | |
1425 goto failed; | |
1426 } | |
1427 | |
1428 imcf->angle = (ngx_uint_t) n; | |
1429 | |
1430 } else { | |
1431 imcf->acv = ngx_palloc(cf->pool, | |
1432 sizeof(ngx_http_complex_value_t)); | |
1433 if (imcf->acv == NULL) { | |
1434 return NGX_CONF_ERROR; | |
1435 } | |
1436 | |
1437 *imcf->acv = cv; | |
1438 } | |
1439 | |
1440 return NGX_CONF_OK; | |
1441 | |
1442 } else { | |
1443 goto failed; | |
1444 } | |
2788 | 1445 } |
1446 | |
1447 if (ngx_strcmp(value[i].data, "resize") == 0) { | |
1448 imcf->filter = NGX_HTTP_IMAGE_RESIZE; | |
1449 | |
1450 } else if (ngx_strcmp(value[i].data, "crop") == 0) { | |
1451 imcf->filter = NGX_HTTP_IMAGE_CROP; | |
1452 | |
1453 } else { | |
1454 goto failed; | |
1455 } | |
1456 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1457 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1458 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1459 ccv.cf = cf; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1460 ccv.value = &value[++i]; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1461 ccv.complex_value = &cv; |
2788 | 1462 |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1463 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1464 return NGX_CONF_ERROR; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1465 } |
2788 | 1466 |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1467 if (cv.lengths == NULL) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1468 n = ngx_http_image_filter_value(&value[i]); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1469 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1470 if (n == 0) { |
2788 | 1471 goto failed; |
1472 } | |
1473 | |
1474 imcf->width = (ngx_uint_t) n; | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1475 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1476 } else { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1477 imcf->wcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1478 if (imcf->wcv == NULL) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1479 return NGX_CONF_ERROR; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1480 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1481 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1482 *imcf->wcv = cv; |
2788 | 1483 } |
1484 | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1485 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1486 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1487 ccv.cf = cf; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1488 ccv.value = &value[++i]; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1489 ccv.complex_value = &cv; |
2788 | 1490 |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1491 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1492 return NGX_CONF_ERROR; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1493 } |
2788 | 1494 |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1495 if (cv.lengths == NULL) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1496 n = ngx_http_image_filter_value(&value[i]); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1497 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1498 if (n == 0) { |
2788 | 1499 goto failed; |
1500 } | |
1501 | |
1502 imcf->height = (ngx_uint_t) n; | |
2998
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1503 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1504 } else { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1505 imcf->hcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1506 if (imcf->hcv == NULL) { |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1507 return NGX_CONF_ERROR; |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1508 } |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1509 |
fa8503fd3647
variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents:
2918
diff
changeset
|
1510 *imcf->hcv = cv; |
2788 | 1511 } |
1512 | |
1513 return NGX_CONF_OK; | |
1514 | |
1515 failed: | |
1516 | |
1517 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", | |
1518 &value[i]); | |
1519 | |
1520 return NGX_CONF_ERROR; | |
1521 } | |
1522 | |
1523 | |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1524 static char * |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1525 ngx_http_image_filter_jpeg_quality(ngx_conf_t *cf, ngx_command_t *cmd, |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1526 void *conf) |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1527 { |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1528 ngx_http_image_filter_conf_t *imcf = conf; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1529 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1530 ngx_str_t *value; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1531 ngx_int_t n; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1532 ngx_http_complex_value_t cv; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1533 ngx_http_compile_complex_value_t ccv; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1534 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1535 value = cf->args->elts; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1536 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1537 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1538 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1539 ccv.cf = cf; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1540 ccv.value = &value[1]; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1541 ccv.complex_value = &cv; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1542 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1543 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1544 return NGX_CONF_ERROR; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1545 } |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1546 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1547 if (cv.lengths == NULL) { |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1548 n = ngx_http_image_filter_value(&value[1]); |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1549 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1550 if (n <= 0) { |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1551 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4307 | 1552 "invalid value \"%V\"", &value[1]); |
3745
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1553 return NGX_CONF_ERROR; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1554 } |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1555 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1556 imcf->jpeg_quality = (ngx_uint_t) n; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1557 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1558 } else { |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1559 imcf->jqcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1560 if (imcf->jqcv == NULL) { |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1561 return NGX_CONF_ERROR; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1562 } |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1563 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1564 *imcf->jqcv = cv; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1565 } |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1566 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1567 return NGX_CONF_OK; |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1568 } |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1569 |
f5fa9d2e09b6
image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents:
3722
diff
changeset
|
1570 |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1571 static char * |
6779
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1572 ngx_http_image_filter_webp_quality(ngx_conf_t *cf, ngx_command_t *cmd, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1573 void *conf) |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1574 { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1575 ngx_http_image_filter_conf_t *imcf = conf; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1576 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1577 ngx_str_t *value; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1578 ngx_int_t n; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1579 ngx_http_complex_value_t cv; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1580 ngx_http_compile_complex_value_t ccv; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1581 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1582 value = cf->args->elts; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1583 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1584 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1585 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1586 ccv.cf = cf; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1587 ccv.value = &value[1]; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1588 ccv.complex_value = &cv; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1589 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1590 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1591 return NGX_CONF_ERROR; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1592 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1593 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1594 if (cv.lengths == NULL) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1595 n = ngx_http_image_filter_value(&value[1]); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1596 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1597 if (n <= 0) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1598 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1599 "invalid value \"%V\"", &value[1]); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1600 return NGX_CONF_ERROR; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1601 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1602 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1603 imcf->webp_quality = (ngx_uint_t) n; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1604 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1605 } else { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1606 imcf->wqcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1607 if (imcf->wqcv == NULL) { |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1608 return NGX_CONF_ERROR; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1609 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1610 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1611 *imcf->wqcv = cv; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1612 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1613 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1614 return NGX_CONF_OK; |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1615 } |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1616 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1617 |
e4b00a021cea
Image filter: support for WebP.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
1618 static char * |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1619 ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd, |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1620 void *conf) |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1621 { |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1622 ngx_http_image_filter_conf_t *imcf = conf; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1623 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1624 ngx_str_t *value; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1625 ngx_int_t n; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1626 ngx_http_complex_value_t cv; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1627 ngx_http_compile_complex_value_t ccv; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1628 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1629 value = cf->args->elts; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1630 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1631 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1632 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1633 ccv.cf = cf; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1634 ccv.value = &value[1]; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1635 ccv.complex_value = &cv; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1636 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1637 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1638 return NGX_CONF_ERROR; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1639 } |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1640 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1641 if (cv.lengths == NULL) { |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1642 n = ngx_http_image_filter_value(&value[1]); |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1643 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1644 if (n < 0) { |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1645 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4307 | 1646 "invalid value \"%V\"", &value[1]); |
4265
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1647 return NGX_CONF_ERROR; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1648 } |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1649 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1650 imcf->sharpen = (ngx_uint_t) n; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1651 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1652 } else { |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1653 imcf->shcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1654 if (imcf->shcv == NULL) { |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1655 return NGX_CONF_ERROR; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1656 } |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1657 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1658 *imcf->shcv = cv; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1659 } |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1660 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1661 return NGX_CONF_OK; |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1662 } |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1663 |
01a7e78ff5a1
The "image_filter_sharpen" directive.
Igor Sysoev <igor@sysoev.ru>
parents:
3910
diff
changeset
|
1664 |
2788 | 1665 static ngx_int_t |
1666 ngx_http_image_filter_init(ngx_conf_t *cf) | |
1667 { | |
1668 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
1669 ngx_http_top_header_filter = ngx_http_image_header_filter; | |
1670 | |
1671 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
1672 ngx_http_top_body_filter = ngx_http_image_body_filter; | |
1673 | |
1674 return NGX_OK; | |
1675 } |