annotate src/http/modules/ngx_http_image_filter_module.c @ 4437:3a1507f48686 stable-1.0

Merge of r4372, r4373, r4374: SCGI fixes: *) Fixed incorrect use of r->http_version in scgi module. The r->http_version is a version of client's request, and modules must not set it unless they are really willing to downgrade protocol version used for a response (i.e. to HTTP/0.9 if no response headers are available). In neither case r->http_version may be upgraded. The former code downgraded response from HTTP/1.1 to HTTP/1.0 for no reason, causing various problems (see ticket #66). It was also possible that HTTP/0.9 requests were upgraded to HTTP/1.0. *) Removed duplicate function declaration. *) Removed error if there is no Status header. The SCGI specification doesn't specify format of the response, and assuming CGI specs should be used there is no reason to complain. RFC 3875 explicitly states that "A Status header field is optional, and status 200 'OK' is assumed if it is omitted".
author Maxim Dounin <mdounin@mdounin.ru>
date Sun, 05 Feb 2012 13:53:50 +0000
parents d0e52213406f
children 4919fb357a5d
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
4 */
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 #include <ngx_config.h>
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
10
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
11 #include <gd.h>
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
12
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 #define NGX_HTTP_IMAGE_OFF 0
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 #define NGX_HTTP_IMAGE_TEST 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 #define NGX_HTTP_IMAGE_SIZE 2
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 #define NGX_HTTP_IMAGE_RESIZE 3
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 #define NGX_HTTP_IMAGE_CROP 4
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
19 #define NGX_HTTP_IMAGE_ROTATE 5
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
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 #define NGX_HTTP_IMAGE_START 0
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 #define NGX_HTTP_IMAGE_READ 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 #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
25 #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
26 #define NGX_HTTP_IMAGE_DONE 4
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
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 #define NGX_HTTP_IMAGE_NONE 0
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 #define NGX_HTTP_IMAGE_JPEG 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 #define NGX_HTTP_IMAGE_GIF 2
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 #define NGX_HTTP_IMAGE_PNG 3
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
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 #define NGX_HTTP_IMAGE_BUFFERED 0x08
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
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 typedef struct {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 ngx_uint_t filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 ngx_uint_t width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
41 ngx_uint_t height;
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
42 ngx_uint_t angle;
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
43 ngx_uint_t jpeg_quality;
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
44 ngx_uint_t sharpen;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
45
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
46 ngx_flag_t transparency;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
47
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
48 ngx_http_complex_value_t *wcv;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
49 ngx_http_complex_value_t *hcv;
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
50 ngx_http_complex_value_t *acv;
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
51 ngx_http_complex_value_t *jqcv;
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
52 ngx_http_complex_value_t *shcv;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
53
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 size_t buffer_size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 } ngx_http_image_filter_conf_t;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 typedef struct {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 u_char *image;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60 u_char *last;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 size_t length;
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 ngx_uint_t width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 ngx_uint_t height;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
66 ngx_uint_t max_width;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
67 ngx_uint_t max_height;
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
68 ngx_uint_t angle;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
69
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70 ngx_uint_t phase;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 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
72 ngx_uint_t force;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 } ngx_http_image_filter_ctx_t;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
76 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
77 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
78 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
79 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
80 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
81 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
82 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83 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
84 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 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
86 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
87 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 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
90 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91 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
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_new(ngx_http_request_t *r, int w, int h,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
94 int colors);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 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
96 gdImagePtr img, int *size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 static void ngx_http_image_cleanup(void *data);
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
98 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
99 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
100 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
101
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 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
104 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
105 void *child);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 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
107 void *conf);
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
108 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
109 ngx_command_t *cmd, void *conf);
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
110 static char *ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
111 void *conf);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 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
113
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 static ngx_command_t ngx_http_image_filter_commands[] = {
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 { ngx_string("image_filter"),
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
118 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 ngx_http_image_filter,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 NGX_HTTP_LOC_CONF_OFFSET,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 NULL },
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
124 { ngx_string("image_filter_jpeg_quality"),
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
125 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
126 ngx_http_image_filter_jpeg_quality,
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
127 NGX_HTTP_LOC_CONF_OFFSET,
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
128 0,
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
129 NULL },
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
130
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
131 { ngx_string("image_filter_sharpen"),
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
132 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
133 ngx_http_image_filter_sharpen,
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
134 NGX_HTTP_LOC_CONF_OFFSET,
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
135 0,
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
136 NULL },
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
137
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
138 { ngx_string("image_filter_transparency"),
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
139 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
140 ngx_conf_set_flag_slot,
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
141 NGX_HTTP_LOC_CONF_OFFSET,
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
142 offsetof(ngx_http_image_filter_conf_t, transparency),
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
143 NULL },
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
144
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 { ngx_string("image_filter_buffer"),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 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
147 ngx_conf_set_size_slot,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 NGX_HTTP_LOC_CONF_OFFSET,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 offsetof(ngx_http_image_filter_conf_t, buffer_size),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 NULL },
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
152 ngx_null_command
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 };
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 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
157 NULL, /* preconfiguration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 ngx_http_image_filter_init, /* postconfiguration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 NULL, /* create main configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 NULL, /* init main configuration */
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 NULL, /* create server configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 NULL, /* merge server configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 ngx_http_image_filter_create_conf, /* create location configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167 ngx_http_image_filter_merge_conf /* merge location configuration */
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171 ngx_module_t ngx_http_image_filter_module = {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172 NGX_MODULE_V1,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 &ngx_http_image_filter_module_ctx, /* module context */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 ngx_http_image_filter_commands, /* module directives */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 NGX_HTTP_MODULE, /* module type */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 NULL, /* init master */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 NULL, /* init module */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178 NULL, /* init process */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 NULL, /* init thread */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 NULL, /* exit thread */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 NULL, /* exit process */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 NULL, /* exit master */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 NGX_MODULE_V1_PADDING
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 };
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 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
188 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
189
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 static ngx_str_t ngx_http_image_types[] = {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 ngx_string("image/jpeg"),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193 ngx_string("image/gif"),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 ngx_string("image/png")
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
197
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 ngx_http_image_header_filter(ngx_http_request_t *r)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201 off_t len;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 ngx_http_image_filter_ctx_t *ctx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203 ngx_http_image_filter_conf_t *conf;
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 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 return ngx_http_next_header_filter(r);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
2834
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
209 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
210
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
211 if (ctx) {
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
212 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
213 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
214 }
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
215
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216 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
217
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
218 if (conf->filter == NGX_HTTP_IMAGE_OFF) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 return ngx_http_next_header_filter(r);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
220 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
221
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
222 if (r->headers_out.content_type.len
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
223 >= sizeof("multipart/x-mixed-replace") - 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 && ngx_strncasecmp(r->headers_out.content_type.data,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225 (u_char *) "multipart/x-mixed-replace",
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 sizeof("multipart/x-mixed-replace") - 1)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 == 0)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 "image filter: multipart/x-mixed-replace response");
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
232 return NGX_ERROR;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235 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
236 if (ctx == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 return NGX_ERROR;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
238 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 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
241
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 len = r->headers_out.content_length_n;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243
2795
d82d08314f78 fix building ngx_http_image_filter_module on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents: 2788
diff changeset
244 if (len != -1 && len > (off_t) conf->buffer_size) {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246 "image filter: too big response: %O", len);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247
3722
1a728cc43bb1 return 415 on too big image in image filter
Igor Sysoev <igor@sysoev.ru>
parents: 3516
diff changeset
248 return NGX_HTTP_UNSUPPORTED_MEDIA_TYPE;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249 }
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 if (len == -1) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 ctx->length = conf->buffer_size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
253
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255 ctx->length = (size_t) len;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 if (r->headers_out.refresh) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259 r->headers_out.refresh->hash = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
261
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 r->main_filter_need_in_memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263 r->allow_ranges = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
264
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
265 return NGX_OK;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270 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
271 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272 ngx_int_t rc;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273 ngx_str_t *ct;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 ngx_chain_t out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275 ngx_http_image_filter_ctx_t *ctx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276 ngx_http_image_filter_conf_t *conf;
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 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
279
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280 if (in == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
281 return ngx_http_next_body_filter(r, in);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
282 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
283
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
284 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
285
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286 if (ctx == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
287 return ngx_http_next_body_filter(r, in);
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290 switch (ctx->phase) {
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 case NGX_HTTP_IMAGE_START:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
293
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
294 ctx->type = ngx_http_image_test(r, in);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
295
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
296 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
297
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
298 if (ctx->type == NGX_HTTP_IMAGE_NONE) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
299
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
300 if (conf->filter == NGX_HTTP_IMAGE_SIZE) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
301 out.buf = ngx_http_image_json(r, NULL);
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 if (out.buf) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
304 out.next = NULL;
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
305 ctx->phase = NGX_HTTP_IMAGE_DONE;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
306
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
307 return ngx_http_image_send(r, ctx, &out);
2788
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 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
310
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
311 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
312 &ngx_http_image_filter_module,
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
313 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
314 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
315
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
316 /* override content type */
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 ct = &ngx_http_image_types[ctx->type - 1];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319 r->headers_out.content_type_len = ct->len;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 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
321 r->headers_out.content_type_lowcase = NULL;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
322
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
323 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
324 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
325
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
326 return ngx_http_image_send(r, ctx, in);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
327 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
328
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329 ctx->phase = NGX_HTTP_IMAGE_READ;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
331 /* fall through */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
332
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
333 case NGX_HTTP_IMAGE_READ:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
334
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
335 rc = ngx_http_image_read(r, in);
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 if (rc == NGX_AGAIN) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 return NGX_OK;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
341 if (rc == NGX_ERROR) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
342 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
343 &ngx_http_image_filter_module,
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
344 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
347 /* fall through */
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 case NGX_HTTP_IMAGE_PROCESS:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351 out.buf = ngx_http_image_process(r);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
352
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
353 if (out.buf == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
354 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
355 &ngx_http_image_filter_module,
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
359 out.next = NULL;
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
360 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
361
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
362 return ngx_http_image_send(r, ctx, &out);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
363
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
364 case NGX_HTTP_IMAGE_PASS:
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
365
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
366 return ngx_http_next_body_filter(r, in);
2788
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 default: /* NGX_HTTP_IMAGE_DONE */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
369
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
370 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
371
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
372 /* 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
373 return (rc == NGX_OK) ? NGX_ERROR : rc;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
374 }
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
375 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
376
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
377
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
378 static ngx_int_t
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
379 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
380 ngx_chain_t *in)
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
381 {
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
382 ngx_int_t rc;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384 rc = ngx_http_next_header_filter(r);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
385
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386 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
387 return NGX_ERROR;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
388 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
390 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
391
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
392 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
393 /* 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
394 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
395 }
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
396
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
397 return rc;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
398 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
399
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
400
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
401 static ngx_uint_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402 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
403 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
404 u_char *p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
406 p = in->buf->pos;
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 if (in->buf->last - p < 16) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
409 return NGX_HTTP_IMAGE_NONE;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
410 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
411
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
412 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
413 "image filter: \"%c%c\"", p[0], p[1]);
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 if (p[0] == 0xff && p[1] == 0xd8) {
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 /* JPEG */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
418
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
419 return NGX_HTTP_IMAGE_JPEG;
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 } 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
422 && p[5] == 'a')
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423 {
2918
0070504324d8 test GIF87a
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
424 if (p[4] == '9' || p[4] == '7') {
0070504324d8 test GIF87a
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
425 /* GIF */
0070504324d8 test GIF87a
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
426 return NGX_HTTP_IMAGE_GIF;
0070504324d8 test GIF87a
Igor Sysoev <igor@sysoev.ru>
parents: 2912
diff changeset
427 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
428
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
429 } 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
430 && 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
431 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
432 /* PNG */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
433
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434 return NGX_HTTP_IMAGE_PNG;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
435 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437 return NGX_HTTP_IMAGE_NONE;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
438 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
439
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 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442 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
443 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
444 u_char *p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445 size_t size, rest;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 ngx_chain_t *cl;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
448 ngx_http_image_filter_ctx_t *ctx;
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 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
451
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
452 if (ctx->image == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
453 ctx->image = ngx_palloc(r->pool, ctx->length);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
454 if (ctx->image == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
455 return NGX_ERROR;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458 ctx->last = ctx->image;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
459 }
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 p = ctx->last;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
462
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
463 for (cl = in; cl; cl = cl->next) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
464
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
465 b = cl->buf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466 size = b->last - b->pos;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
467
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
468 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
469 "image buf: %uz", size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471 rest = ctx->image + ctx->length - p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472 size = (rest < size) ? rest : size;
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 p = ngx_cpymem(p, b->pos, size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
475 b->pos += size;
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 if (b->last_buf) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478 ctx->last = p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479 return NGX_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
480 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
481 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
482
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
483 ctx->last = p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
484 r->connection->buffered |= NGX_HTTP_IMAGE_BUFFERED;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
486 return NGX_AGAIN;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
489
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
490 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
491 ngx_http_image_process(ngx_http_request_t *r)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
492 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
493 ngx_int_t rc;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
494 ngx_http_image_filter_ctx_t *ctx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495 ngx_http_image_filter_conf_t *conf;
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 r->connection->buffered &= ~NGX_HTTP_IMAGE_BUFFERED;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
498
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
499 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
500
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
501 rc = ngx_http_image_size(r, ctx);
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 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
504
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
505 if (conf->filter == NGX_HTTP_IMAGE_SIZE) {
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
506 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
507 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
508
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
509 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
510
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
511 if (conf->filter == NGX_HTTP_IMAGE_ROTATE) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
512
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
513 if (ctx->angle != 90 && ctx->angle != 180 && ctx->angle != 270) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
514 return NULL;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
515 }
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
516
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
517 return ngx_http_image_resize(r, ctx);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
518 }
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
519
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
520 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
521 if (ctx->max_width == 0) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
522 return NULL;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
523 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
524
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
525 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
526 conf->height);
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
527 if (ctx->max_height == 0) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
528 return NULL;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
529 }
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
530
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
531 if (rc == NGX_OK
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
532 && 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
533 && ctx->height <= ctx->max_height
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
534 && 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
535 && !ctx->force)
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
536 {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
537 return ngx_http_image_asis(r, ctx);
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
538 }
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
539
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
540 return ngx_http_image_resize(r, ctx);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
541 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
542
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
543
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
544 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
545 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
546 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
547 size_t len;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
548 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
549
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
550 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
551 if (b == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
552 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
553 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
554
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
555 b->memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
556 b->last_buf = 1;
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 ngx_http_clean_header(r);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
559
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
560 r->headers_out.status = NGX_HTTP_OK;
3516
dd1570b6f237 ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents: 3394
diff changeset
561 ngx_str_set(&r->headers_out.content_type, "text/plain");
2882
896db5a09bd2 reset content_type hash value, this fixes a bug when XSLT responses
Igor Sysoev <igor@sysoev.ru>
parents: 2848
diff changeset
562 r->headers_out.content_type_lowcase = NULL;
2788
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 if (ctx == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
565 b->pos = (u_char *) "{}" CRLF;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
566 b->last = b->pos + sizeof("{}" CRLF) - 1;
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 ngx_http_image_length(r, b);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
569
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
570 return b;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
573 len = sizeof("{ \"img\" : "
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
574 "{ \"width\": , \"height\": , \"type\": \"jpeg\" } }" CRLF) - 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
575 + 2 * NGX_SIZE_T_LEN;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
576
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577 b->pos = ngx_pnalloc(r->pool, len);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578 if (b->pos == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
580 }
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 b->last = ngx_sprintf(b->pos,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
583 "{ \"img\" : "
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584 "{ \"width\": %uz,"
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
585 " \"height\": %uz,"
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
586 " \"type\": \"%s\" } }" CRLF,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
587 ctx->width, ctx->height,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
588 ngx_http_image_types[ctx->type - 1].data + 6);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
589
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
590 ngx_http_image_length(r, b);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
591
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
592 return b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
593 }
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 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
597 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
598 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
599 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
601 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
602 if (b == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
603 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604 }
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 b->pos = ctx->image;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
607 b->last = ctx->last;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
608 b->memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
609 b->last_buf = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611 ngx_http_image_length(r, b);
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 return 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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
616
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
617 static void
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
618 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
619 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
620 r->headers_out.content_length_n = b->last - b->pos;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
621
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
622 if (r->headers_out.content_length) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
623 r->headers_out.content_length->hash = 0;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626 r->headers_out.content_length = NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
627 }
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 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
631 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
632 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
633 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
634 size_t len, app;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635 ngx_uint_t width, height;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
636
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
637 p = ctx->image;
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 switch (ctx->type) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
640
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641 case NGX_HTTP_IMAGE_JPEG:
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 p += 2;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644 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
645 width = 0;
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
646 height = 0;
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
647 app = 0;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
648
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649 while (p < last) {
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 if (p[0] == 0xff && p[1] != 0xff) {
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 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3393
fbf6d83ce288 style fix
Igor Sysoev <igor@sysoev.ru>
parents: 3134
diff changeset
654 "JPEG: %02xd %02xd", p[0], p[1]);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656 p++;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657
3394
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
658 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
659 || *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
660 && (width == 0 || height == 0))
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661 {
3394
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
662 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
663 height = p[4] * 256 + p[5];
2788
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
666 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
667 "JPEG: %02xd %02xd", p[1], p[2]);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668
3394
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
669 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
670
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
671 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
672 /* 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
673 app += len;
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
674 }
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
675
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
676 p += len;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
678 continue;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681 p++;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
682 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
683
3394
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
684 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
685 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
686 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
687
3394
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
688 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
689 /* 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
690 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
691 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
692 "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
693 }
2788
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 break;
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 case NGX_HTTP_IMAGE_GIF:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
698
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
699 if (ctx->length < 10) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
700 return NGX_DECLINED;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
701 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
702
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
703 width = p[7] * 256 + p[6];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704 height = p[9] * 256 + p[8];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
705
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
706 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
708 case NGX_HTTP_IMAGE_PNG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
709
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
710 if (ctx->length < 24) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
711 return NGX_DECLINED;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
714 width = p[18] * 256 + p[19];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
715 height = p[22] * 256 + p[23];
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 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
719 default:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
720
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
721 return NGX_DECLINED;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
722 }
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 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
725 "image size: %d x %d", width, height);
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 ctx->width = width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
728 ctx->height = height;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
729
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
730 return NGX_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
731 }
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
734 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
735 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
736 {
3910
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
737 int sx, sy, dx, dy, ox, oy, ax, ay, size,
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
738 colors, palette, transparent, sharpen,
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
739 red, green, blue, t;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
740 u_char *out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
741 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742 ngx_uint_t resize;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743 gdImagePtr src, dst;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 ngx_pool_cleanup_t *cln;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
745 ngx_http_image_filter_conf_t *conf;
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 src = ngx_http_image_source(r, ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
748
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
749 if (src == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
750 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
751 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
752
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
753 sx = gdImageSX(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
754 sy = gdImageSY(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
755
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756 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
757
3394
11965c62b92c force image filter conversion if JPEG application data consume more than 5%
Igor Sysoev <igor@sysoev.ru>
parents: 3393
diff changeset
758 if (!ctx->force
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
759 && 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
760 && (ngx_uint_t) sx <= ctx->max_width
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
761 && (ngx_uint_t) sy <= ctx->max_height)
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
762 {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
763 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
764 return ngx_http_image_asis(r, ctx);
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 colors = gdImageColorsTotal(src);
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
768
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
769 if (colors && conf->transparency) {
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
770 transparent = gdImageGetTransparent(src);
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
771
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
772 if (transparent != -1) {
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
773 palette = colors;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
774 red = gdImageRed(src, transparent);
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
775 green = gdImageGreen(src, transparent);
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
776 blue = gdImageBlue(src, transparent);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
777
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
778 goto transparent;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
779 }
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
780 }
3117
e2a510ac53db fix transparency in GIF
Igor Sysoev <igor@sysoev.ru>
parents: 2998
diff changeset
781
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
782 palette = 0;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
783 transparent = -1;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
784 red = 0;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
785 green = 0;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
786 blue = 0;
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
787
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
788 transparent:
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
789
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
790 gdImageColorTransparent(src, -1);
3117
e2a510ac53db fix transparency in GIF
Igor Sysoev <igor@sysoev.ru>
parents: 2998
diff changeset
791
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
792 dx = sx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
793 dy = sy;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
794
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
795 if (conf->filter == NGX_HTTP_IMAGE_RESIZE) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
796
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
797 if ((ngx_uint_t) dx > ctx->max_width) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
798 dy = dy * ctx->max_width / dx;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
799 dy = dy ? dy : 1;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
800 dx = ctx->max_width;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
801 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
802
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
803 if ((ngx_uint_t) dy > ctx->max_height) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
804 dx = dx * ctx->max_height / dy;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
805 dx = dx ? dx : 1;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
806 dy = ctx->max_height;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
807 }
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 resize = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
810
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
811 } else if (conf->filter == NGX_HTTP_IMAGE_ROTATE) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
812
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
813 resize = 0;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
814
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
815 } else { /* NGX_HTTP_IMAGE_CROP */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
816
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
817 resize = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
818
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
819 if ((ngx_uint_t) (dx * 100 / dy)
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
820 < ctx->max_width * 100 / ctx->max_height)
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
821 {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
822 if ((ngx_uint_t) dx > ctx->max_width) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
823 dy = dy * ctx->max_width / dx;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
824 dy = dy ? dy : 1;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
825 dx = ctx->max_width;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
826 resize = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
827 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
828
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
829 } else {
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
830 if ((ngx_uint_t) dy > ctx->max_height) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
831 dx = dx * ctx->max_height / dy;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
832 dx = dx ? dx : 1;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
833 dy = ctx->max_height;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
834 resize = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
835 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
836 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
837 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
838
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
839 if (resize) {
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
840 dst = ngx_http_image_new(r, dx, dy, palette);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
841 if (dst == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
842 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
843 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
844 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
845
3133
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
846 if (colors == 0) {
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
847 gdImageSaveAlpha(dst, 1);
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
848 gdImageAlphaBlending(dst, 0);
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
849 }
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
850
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
851 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
852
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
853 if (colors) {
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
854 gdImageTrueColorToPalette(dst, 1, 256);
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
855 }
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
856
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
857 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
858
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
859 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
860 dst = src;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
861 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
862
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
863 if (ctx->angle) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
864 src = dst;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
865
3910
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
866 ax = (dx % 2 == 0) ? 1 : 0;
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
867 ay = (dy % 2 == 0) ? 1 : 0;
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
868
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
869 switch (ctx->angle) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
870
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
871 case 90:
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
872 case 270:
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
873 dst = ngx_http_image_new(r, dy, dx, palette);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
874 if (dst == NULL) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
875 gdImageDestroy(src);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
876 return NULL;
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 if (ctx->angle == 90) {
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
879 ox = dy / 2 + ay;
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
880 oy = dx / 2 - ax;
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
881
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
882 } else {
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
883 ox = dy / 2 - ay;
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
884 oy = dx / 2 + ax;
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
885 }
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
886
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
887 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
888 dx + ax, dy + ay, ctx->angle);
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
889 gdImageDestroy(src);
3884
ea712f4dc030 fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents: 3878
diff changeset
890
ea712f4dc030 fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents: 3878
diff changeset
891 t = dx;
ea712f4dc030 fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents: 3878
diff changeset
892 dx = dy;
ea712f4dc030 fix "image_filter rotate 180" and crop case
Igor Sysoev <igor@sysoev.ru>
parents: 3878
diff changeset
893 dy = t;
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
894 break;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
895
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
896 case 180:
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
897 dst = ngx_http_image_new(r, dx, dy, palette);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
898 if (dst == NULL) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
899 gdImageDestroy(src);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
900 return NULL;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
901 }
3910
750fb808aa15 gdImageCopyRotated() may images of even height or width
Igor Sysoev <igor@sysoev.ru>
parents: 3884
diff changeset
902 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
903 dx + ax, dy + ay, ctx->angle);
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
904 gdImageDestroy(src);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
905 break;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
906 }
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
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
909 if (conf->filter == NGX_HTTP_IMAGE_CROP) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
910
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
911 src = dst;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
912
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
913 if ((ngx_uint_t) dx > ctx->max_width) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
914 ox = dx - ctx->max_width;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
915
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
916 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
917 ox = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
918 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
919
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
920 if ((ngx_uint_t) dy > ctx->max_height) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
921 oy = dy - ctx->max_height;
2788
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 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
924 oy = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
925 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
926
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
927 if (ox || oy) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
928
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
929 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
930
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
931 if (dst == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
932 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
933 return NULL;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
936 ox /= 2;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
937 oy /= 2;
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 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
940 "image crop: %d x %d @ %d x %d",
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
941 dx, dy, ox, oy);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
942
3133
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
943 if (colors == 0) {
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
944 gdImageSaveAlpha(dst, 1);
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
945 gdImageAlphaBlending(dst, 0);
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
946 }
28a6aa24b453 fix alpha-channel transparency in PNG
Igor Sysoev <igor@sysoev.ru>
parents: 3117
diff changeset
947
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
948 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
949
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
950 if (colors) {
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
951 gdImageTrueColorToPalette(dst, 1, 256);
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
952 }
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
953
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
954 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
955 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
956 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
957
3117
e2a510ac53db fix transparency in GIF
Igor Sysoev <igor@sysoev.ru>
parents: 2998
diff changeset
958 if (transparent != -1 && colors) {
e2a510ac53db fix transparency in GIF
Igor Sysoev <igor@sysoev.ru>
parents: 2998
diff changeset
959 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue));
e2a510ac53db fix transparency in GIF
Igor Sysoev <igor@sysoev.ru>
parents: 2998
diff changeset
960 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
961
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
962 sharpen = ngx_http_image_filter_get_value(r, conf->shcv, conf->sharpen);
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
963 if (sharpen > 0) {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
964 gdImageSharpen(dst, sharpen);
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
965 }
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
966
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
967 out = ngx_http_image_out(r, ctx->type, dst, &size);
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 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
970 "image: %d x %d %d", sx, sy, colors);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
971
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
972 gdImageDestroy(dst);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
973 ngx_pfree(r->pool, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
974
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
975 if (out == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
976 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
977 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
978
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
979 cln = ngx_pool_cleanup_add(r->pool, 0);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
980 if (cln == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
981 gdFree(out);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
982 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
983 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
984
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
985 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
986 if (b == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
987 gdFree(out);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
988 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
989 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
990
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
991 cln->handler = ngx_http_image_cleanup;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
992 cln->data = out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
993
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
994 b->pos = out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
995 b->last = out + size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
996 b->memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
997 b->last_buf = 1;
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 ngx_http_image_length(r, b);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1000
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1001 return b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1002 }
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 static gdImagePtr
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1006 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
1007 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1008 char *failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1009 gdImagePtr img;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1010
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1011 img = NULL;
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 switch (ctx->type) {
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 case NGX_HTTP_IMAGE_JPEG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1016 img = gdImageCreateFromJpegPtr(ctx->length, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1017 failed = "gdImageCreateFromJpegPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1018 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1019
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1020 case NGX_HTTP_IMAGE_GIF:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1021 img = gdImageCreateFromGifPtr(ctx->length, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1022 failed = "gdImageCreateFromGifPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1023 break;
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 case NGX_HTTP_IMAGE_PNG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1026 img = gdImageCreateFromPngPtr(ctx->length, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1027 failed = "gdImageCreateFromPngPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1028 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1029
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1030 default:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1031 failed = "unknown image type";
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1035 if (img == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1036 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
1037 }
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 return img;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1040 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1041
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1042
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1043 static gdImagePtr
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1044 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
1045 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1046 gdImagePtr img;
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 if (colors == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1049 img = gdImageCreateTrueColor(w, h);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1050
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1051 if (img == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1052 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1053 "gdImageCreateTrueColor() failed");
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1054 return NULL;
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 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1058 img = gdImageCreate(w, h);
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 if (img == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1061 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1062 "gdImageCreate() failed");
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1063 return NULL;
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 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1066
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1067 return img;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1068 }
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 static u_char *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1072 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
1073 int *size)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1074 {
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1075 char *failed;
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1076 u_char *out;
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1077 ngx_int_t jq;
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1078 ngx_http_image_filter_conf_t *conf;
2788
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 out = NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1081
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1082 switch (type) {
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 case NGX_HTTP_IMAGE_JPEG:
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1085 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
1086
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1087 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
1088 if (jq <= 0) {
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1089 return NULL;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1090 }
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1091
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1092 out = gdImageJpegPtr(img, size, jq);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1093 failed = "gdImageJpegPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1094 break;
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 case NGX_HTTP_IMAGE_GIF:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1097 out = gdImageGifPtr(img, size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1098 failed = "gdImageGifPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1099 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1100
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1101 case NGX_HTTP_IMAGE_PNG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1102 out = gdImagePngPtr(img, size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1103 failed = "gdImagePngPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1104 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1105
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1106 default:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1107 failed = "unknown image type";
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1111 if (out == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1112 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
1113 }
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 return out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1116 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1117
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1118
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1119 static void
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1120 ngx_http_image_cleanup(void *data)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1121 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1122 gdFree(data);
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
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1126 static ngx_uint_t
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1127 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
1128 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
1129 {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1130 ngx_str_t val;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1131
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1132 if (cv == NULL) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1133 return v;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1134 }
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1135
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1136 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
1137 return 0;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1138 }
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1139
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1140 return ngx_http_image_filter_value(&val);
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1141 }
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1142
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 static ngx_uint_t
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1145 ngx_http_image_filter_value(ngx_str_t *value)
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1146 {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1147 ngx_int_t n;
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 if (value->len == 1 && value->data[0] == '-') {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1150 return (ngx_uint_t) -1;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1151 }
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 n = ngx_atoi(value->data, value->len);
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1154
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1155 if (n > 0) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1156 return (ngx_uint_t) n;
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
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1159 return 0;
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
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1162
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1163 static void *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1164 ngx_http_image_filter_create_conf(ngx_conf_t *cf)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1165 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1166 ngx_http_image_filter_conf_t *conf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1167
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1168 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
1169 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
1170 return NULL;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1171 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1172
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1173 conf->filter = NGX_CONF_UNSET_UINT;
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1174 conf->jpeg_quality = NGX_CONF_UNSET_UINT;
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1175 conf->sharpen = NGX_CONF_UNSET_UINT;
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1176 conf->angle = NGX_CONF_UNSET_UINT;
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
1177 conf->transparency = NGX_CONF_UNSET;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1178 conf->buffer_size = NGX_CONF_UNSET_SIZE;
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 return 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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1183
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1184 static char *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1185 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
1186 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1187 ngx_http_image_filter_conf_t *prev = parent;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1188 ngx_http_image_filter_conf_t *conf = child;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1189
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1190 if (conf->filter == NGX_CONF_UNSET_UINT) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1191
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1192 if (prev->filter == NGX_CONF_UNSET_UINT) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1193 conf->filter = NGX_HTTP_IMAGE_OFF;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1194
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1195 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1196 conf->filter = prev->filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1197 conf->width = prev->width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1198 conf->height = prev->height;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1199 conf->wcv = prev->wcv;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1200 conf->hcv = prev->hcv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1201 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1202 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1203
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1204 /* 75 is libjpeg default quality */
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1205 ngx_conf_merge_uint_value(conf->jpeg_quality, prev->jpeg_quality, 75);
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1206
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1207 if (conf->jqcv == NULL) {
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1208 conf->jqcv = prev->jqcv;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1209 }
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1210
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1211 ngx_conf_merge_uint_value(conf->sharpen, prev->sharpen, 0);
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1212
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1213 if (conf->shcv == NULL) {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1214 conf->shcv = prev->shcv;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1215 }
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1216
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1217 ngx_conf_merge_uint_value(conf->angle, prev->angle, 0);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1218 if (conf->acv == NULL) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1219 conf->acv = prev->acv;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1220 }
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1221
3134
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
1222 ngx_conf_merge_value(conf->transparency, prev->transparency, 1);
e6f5cb5eff8b image_filter_transparency
Igor Sysoev <igor@sysoev.ru>
parents: 3133
diff changeset
1223
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1224 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
1225 1 * 1024 * 1024);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1226
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1227 return NGX_CONF_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1228 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1229
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 static char *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1232 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
1233 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1234 ngx_http_image_filter_conf_t *imcf = conf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1235
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1236 ngx_str_t *value;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1237 ngx_int_t n;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1238 ngx_uint_t i;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1239 ngx_http_complex_value_t cv;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1240 ngx_http_compile_complex_value_t ccv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1241
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1242 value = cf->args->elts;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1243
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1244 i = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1245
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1246 if (cf->args->nelts == 2) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1247 if (ngx_strcmp(value[i].data, "off") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1248 imcf->filter = NGX_HTTP_IMAGE_OFF;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1249
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1250 } else if (ngx_strcmp(value[i].data, "test") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1251 imcf->filter = NGX_HTTP_IMAGE_TEST;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1252
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1253 } else if (ngx_strcmp(value[i].data, "size") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1254 imcf->filter = NGX_HTTP_IMAGE_SIZE;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1255
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1256 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1257 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1258 }
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 return NGX_CONF_OK;
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1261
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1262 } else if (cf->args->nelts == 3) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1263
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1264 if (ngx_strcmp(value[i].data, "rotate") == 0) {
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1265 if (imcf->filter != NGX_HTTP_IMAGE_RESIZE
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1266 && imcf->filter != NGX_HTTP_IMAGE_CROP)
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1267 {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1268 imcf->filter = NGX_HTTP_IMAGE_ROTATE;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1269 }
3878
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1270
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1271 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1272
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1273 ccv.cf = cf;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1274 ccv.value = &value[++i];
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1275 ccv.complex_value = &cv;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1276
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1277 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1278 return NGX_CONF_ERROR;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1279 }
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1280
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1281 if (cv.lengths == NULL) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1282 n = ngx_http_image_filter_value(&value[i]);
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1283
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1284 if (n != 90 && n != 180 && n != 270) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1285 goto failed;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1286 }
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1287
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1288 imcf->angle = (ngx_uint_t) n;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1289
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1290 } else {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1291 imcf->acv = ngx_palloc(cf->pool,
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1292 sizeof(ngx_http_complex_value_t));
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1293 if (imcf->acv == NULL) {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1294 return NGX_CONF_ERROR;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1295 }
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1296
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1297 *imcf->acv = cv;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1298 }
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1299
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1300 return NGX_CONF_OK;
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 } else {
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1303 goto failed;
7562ee4feb74 image filter rotate
Igor Sysoev <igor@sysoev.ru>
parents: 3745
diff changeset
1304 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1305 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1306
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1307 if (ngx_strcmp(value[i].data, "resize") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1308 imcf->filter = NGX_HTTP_IMAGE_RESIZE;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1309
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1310 } else if (ngx_strcmp(value[i].data, "crop") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1311 imcf->filter = NGX_HTTP_IMAGE_CROP;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1312
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1313 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1314 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1315 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1316
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1317 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
1318
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1319 ccv.cf = cf;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1320 ccv.value = &value[++i];
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1321 ccv.complex_value = &cv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1322
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1323 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1324 return NGX_CONF_ERROR;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1325 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1326
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1327 if (cv.lengths == NULL) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1328 n = ngx_http_image_filter_value(&value[i]);
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1329
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1330 if (n == 0) {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1331 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1332 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1333
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1334 imcf->width = (ngx_uint_t) n;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1335
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1336 } else {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1337 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
1338 if (imcf->wcv == NULL) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1339 return NGX_CONF_ERROR;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1340 }
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1341
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1342 *imcf->wcv = cv;
2788
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
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1345 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
1346
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1347 ccv.cf = cf;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1348 ccv.value = &value[++i];
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1349 ccv.complex_value = &cv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1350
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1351 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1352 return NGX_CONF_ERROR;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1353 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1354
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1355 if (cv.lengths == NULL) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1356 n = ngx_http_image_filter_value(&value[i]);
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1357
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1358 if (n == 0) {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1359 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1360 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1361
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1362 imcf->height = (ngx_uint_t) n;
2998
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1363
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1364 } else {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1365 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
1366 if (imcf->hcv == NULL) {
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1367 return NGX_CONF_ERROR;
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1368 }
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1369
fa8503fd3647 variables support in image_filter
Igor Sysoev <igor@sysoev.ru>
parents: 2918
diff changeset
1370 *imcf->hcv = cv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1371 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1372
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1373 return NGX_CONF_OK;
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 failed:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1376
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1377 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
1378 &value[i]);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1379
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1380 return NGX_CONF_ERROR;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1381 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1382
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1383
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1384 static char *
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1385 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
1386 void *conf)
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1387 {
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1388 ngx_http_image_filter_conf_t *imcf = conf;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1389
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1390 ngx_str_t *value;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1391 ngx_int_t n;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1392 ngx_http_complex_value_t cv;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1393 ngx_http_compile_complex_value_t ccv;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1394
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1395 value = cf->args->elts;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1396
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1397 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
1398
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1399 ccv.cf = cf;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1400 ccv.value = &value[1];
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1401 ccv.complex_value = &cv;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1402
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1403 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
1404 return NGX_CONF_ERROR;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1405 }
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1406
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1407 if (cv.lengths == NULL) {
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1408 n = ngx_http_image_filter_value(&value[1]);
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1409
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1410 if (n <= 0) {
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1411 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1412 "invalid value \"%V\"", &value[1]);
3745
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1413 return NGX_CONF_ERROR;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1414 }
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1415
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1416 imcf->jpeg_quality = (ngx_uint_t) n;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1417
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1418 } else {
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1419 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
1420 if (imcf->jqcv == NULL) {
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1421 return NGX_CONF_ERROR;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1422 }
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1423
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1424 *imcf->jqcv = cv;
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
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1427 return NGX_CONF_OK;
f5fa9d2e09b6 image_filter_jpeg_quality supports variables
Igor Sysoev <igor@sysoev.ru>
parents: 3722
diff changeset
1428 }
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
4355
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1431 static char *
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1432 ngx_http_image_filter_sharpen(ngx_conf_t *cf, ngx_command_t *cmd,
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1433 void *conf)
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1434 {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1435 ngx_http_image_filter_conf_t *imcf = conf;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1436
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1437 ngx_str_t *value;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1438 ngx_int_t n;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1439 ngx_http_complex_value_t cv;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1440 ngx_http_compile_complex_value_t ccv;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1441
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1442 value = cf->args->elts;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1443
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1444 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1445
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1446 ccv.cf = cf;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1447 ccv.value = &value[1];
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1448 ccv.complex_value = &cv;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1449
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1450 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1451 return NGX_CONF_ERROR;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1452 }
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1453
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1454 if (cv.lengths == NULL) {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1455 n = ngx_http_image_filter_value(&value[1]);
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1456
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1457 if (n < 0) {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1458 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1459 "invalid value \"%V\"", &value[1]);
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1460 return NGX_CONF_ERROR;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1461 }
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1462
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1463 imcf->sharpen = (ngx_uint_t) n;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1464
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1465 } else {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1466 imcf->shcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1467 if (imcf->shcv == NULL) {
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1468 return NGX_CONF_ERROR;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1469 }
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1470
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1471 *imcf->shcv = cv;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1472 }
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1473
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1474 return NGX_CONF_OK;
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1475 }
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1476
d0e52213406f Merge of r4266, r4308, r4309:
Maxim Dounin <mdounin@mdounin.ru>
parents: 3910
diff changeset
1477
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1478 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1479 ngx_http_image_filter_init(ngx_conf_t *cf)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1480 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1481 ngx_http_next_header_filter = ngx_http_top_header_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1482 ngx_http_top_header_filter = ngx_http_image_header_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1483
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1484 ngx_http_next_body_filter = ngx_http_top_body_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1485 ngx_http_top_body_filter = ngx_http_image_body_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1486
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1487 return NGX_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1488 }