annotate src/http/modules/ngx_http_image_filter_module.c @ 5348:317e0893a1e6

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