annotate src/http/modules/ngx_http_image_filter_module.c @ 3440:88741ec7731a stable-0.7

merge r3294, r3305: Fix a bug introduced in r2032: After a child process has read a terminate message from a channel, the process tries to read the channel again. The kernel (at least FreeBSD) may preempt the process and sends a SIGIO signal to a master process. The master process sends a new terminate message, the kernel switches again to the the child process, and the child process reads the messages instead of an EAGAIN error. And this may repeat over and over. Being that the child process can not exit the cycle and test the termination flag set by the message handler. The fix disallow the master process to send a new terminate message on SIGIO signal reception. It may send the message only on SIGALARM signal.
author Igor Sysoev <igor@sysoev.ru>
date Mon, 01 Feb 2010 15:49:36 +0000
parents 8b2d478de54b
children d87088142876
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19
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 #define NGX_HTTP_IMAGE_START 0
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 #define NGX_HTTP_IMAGE_READ 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 #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
24 #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
25 #define NGX_HTTP_IMAGE_DONE 4
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26
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 #define NGX_HTTP_IMAGE_NONE 0
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 #define NGX_HTTP_IMAGE_JPEG 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 #define NGX_HTTP_IMAGE_GIF 2
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 #define NGX_HTTP_IMAGE_PNG 3
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32
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 #define NGX_HTTP_IMAGE_BUFFERED 0x08
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37 typedef struct {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 ngx_uint_t filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
39 ngx_uint_t width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
40 ngx_uint_t height;
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
41 ngx_int_t jpeg_quality;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
42
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
43 ngx_flag_t transparency;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
44
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
45 ngx_http_complex_value_t *wcv;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
46 ngx_http_complex_value_t *hcv;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
47
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
48 size_t buffer_size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
49 } ngx_http_image_filter_conf_t;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
50
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52 typedef struct {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
53 u_char *image;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
54 u_char *last;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56 size_t length;
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 ngx_uint_t width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 ngx_uint_t height;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
61 ngx_uint_t max_width;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
62 ngx_uint_t max_height;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
63
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 ngx_uint_t phase;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65 ngx_uint_t type;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 } ngx_http_image_filter_ctx_t;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
69 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
70 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
71 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
72 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
73 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
74 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
75 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 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
77 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 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
79 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
80 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 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
83 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 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
85 ngx_http_image_filter_ctx_t *ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 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
87 int colors);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 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
89 gdImagePtr img, int *size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90 static void ngx_http_image_cleanup(void *data);
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
91 static ngx_uint_t ngx_http_image_filter_get_value(ngx_http_request_t *r,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
92 ngx_http_complex_value_t *cv, ngx_uint_t v);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
93 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
94
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 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
97 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
98 void *child);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99 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
100 void *conf);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 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
102
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 static ngx_command_t ngx_http_image_filter_commands[] = {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 { ngx_string("image_filter"),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 NGX_HTTP_LOC_CONF|NGX_CONF_TAKE13,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108 ngx_http_image_filter,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 NGX_HTTP_LOC_CONF_OFFSET,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111 NULL },
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
113 { ngx_string("image_filter_jpeg_quality"),
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
114 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
115 ngx_conf_set_num_slot,
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
116 NGX_HTTP_LOC_CONF_OFFSET,
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
117 offsetof(ngx_http_image_filter_conf_t, jpeg_quality),
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
118 NULL },
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
119
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
120 { ngx_string("image_filter_transparency"),
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
121 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
122 ngx_conf_set_flag_slot,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
123 NGX_HTTP_LOC_CONF_OFFSET,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
124 offsetof(ngx_http_image_filter_conf_t, transparency),
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
125 NULL },
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
126
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 { ngx_string("image_filter_buffer"),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 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
129 ngx_conf_set_size_slot,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 NGX_HTTP_LOC_CONF_OFFSET,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 offsetof(ngx_http_image_filter_conf_t, buffer_size),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132 NULL },
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 ngx_null_command
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 };
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
137
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
138 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
139 NULL, /* preconfiguration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
140 ngx_http_image_filter_init, /* postconfiguration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
141
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 NULL, /* create main configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 NULL, /* init main configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
144
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 NULL, /* create server configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 NULL, /* merge server configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
148 ngx_http_image_filter_create_conf, /* create location configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149 ngx_http_image_filter_merge_conf /* merge location configuration */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 };
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 ngx_module_t ngx_http_image_filter_module = {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 NGX_MODULE_V1,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 &ngx_http_image_filter_module_ctx, /* module context */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 ngx_http_image_filter_commands, /* module directives */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157 NGX_HTTP_MODULE, /* module type */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 NULL, /* init master */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 NULL, /* init module */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 NULL, /* init process */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 NULL, /* init thread */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 NULL, /* exit thread */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 NULL, /* exit process */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 NULL, /* exit master */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 NGX_MODULE_V1_PADDING
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166 };
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
167
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 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
170 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
171
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 static ngx_str_t ngx_http_image_types[] = {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 ngx_string("image/jpeg"),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 ngx_string("image/gif"),
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176 ngx_string("image/png")
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 };
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
181 ngx_http_image_header_filter(ngx_http_request_t *r)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 off_t len;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 ngx_http_image_filter_ctx_t *ctx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185 ngx_http_image_filter_conf_t *conf;
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 if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188 return ngx_http_next_header_filter(r);
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
2834
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
191 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
192
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
193 if (ctx) {
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
194 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
195 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
196 }
0449d289256c test finalized image filter context before testing image_filter off
Igor Sysoev <igor@sysoev.ru>
parents: 2821
diff changeset
197
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 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
199
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 if (conf->filter == NGX_HTTP_IMAGE_OFF) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201 return ngx_http_next_header_filter(r);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
202 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
203
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
204 if (r->headers_out.content_type.len
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
205 >= sizeof("multipart/x-mixed-replace") - 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
206 && ngx_strncasecmp(r->headers_out.content_type.data,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
207 (u_char *) "multipart/x-mixed-replace",
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208 sizeof("multipart/x-mixed-replace") - 1)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209 == 0)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
210 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
211 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212 "image filter: multipart/x-mixed-replace response");
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 return NGX_ERROR;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
216
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
217 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
218 if (ctx == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
219 return NGX_ERROR;
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 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
223
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
224 len = r->headers_out.content_length_n;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
225
2795
d82d08314f78 fix building ngx_http_image_filter_module on 64-bit platforms
Igor Sysoev <igor@sysoev.ru>
parents: 2788
diff changeset
226 if (len != -1 && len > (off_t) conf->buffer_size) {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
228 "image filter: too big response: %O", len);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
230 return NGX_ERROR;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 if (len == -1) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 ctx->length = conf->buffer_size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
235
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
236 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 ctx->length = (size_t) len;
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 if (r->headers_out.refresh) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 r->headers_out.refresh->hash = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244 r->main_filter_need_in_memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
245 r->allow_ranges = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
246
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
247 return NGX_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
249
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 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
252 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
253 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
254 ngx_int_t rc;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
255 ngx_str_t *ct;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
256 ngx_chain_t out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
257 ngx_http_image_filter_ctx_t *ctx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
258 ngx_http_image_filter_conf_t *conf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
259
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
260 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
261
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
262 if (in == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
263 return ngx_http_next_body_filter(r, in);
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
266 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
267
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
268 if (ctx == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
269 return ngx_http_next_body_filter(r, in);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
270 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
271
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272 switch (ctx->phase) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
273
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
274 case NGX_HTTP_IMAGE_START:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
275
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
276 ctx->type = ngx_http_image_test(r, in);
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 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
279
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
280 if (ctx->type == NGX_HTTP_IMAGE_NONE) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
281
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
282 if (conf->filter == NGX_HTTP_IMAGE_SIZE) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
283 out.buf = ngx_http_image_json(r, NULL);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
284
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
285 if (out.buf) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
286 out.next = NULL;
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
287 ctx->phase = NGX_HTTP_IMAGE_DONE;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
288
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
289 return ngx_http_image_send(r, ctx, &out);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
291 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
292
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
293 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
294 &ngx_http_image_filter_module,
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
295 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
296 }
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 /* override content type */
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 ct = &ngx_http_image_types[ctx->type - 1];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
301 r->headers_out.content_type_len = ct->len;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
302 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
303 r->headers_out.content_type_lowcase = NULL;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
304
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
305 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
306 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
307
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
308 return ngx_http_image_send(r, ctx, in);
2788
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 ctx->phase = NGX_HTTP_IMAGE_READ;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
312
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
313 /* fall through */
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 case NGX_HTTP_IMAGE_READ:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
316
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
317 rc = ngx_http_image_read(r, in);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
318
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
319 if (rc == NGX_AGAIN) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
320 return NGX_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
321 }
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 (rc == NGX_ERROR) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
324 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
325 &ngx_http_image_filter_module,
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
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 /* fall through */
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 case NGX_HTTP_IMAGE_PROCESS:
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 out.buf = ngx_http_image_process(r);
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 if (out.buf == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
336 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
337 &ngx_http_image_filter_module,
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
338 NGX_HTTP_UNSUPPORTED_MEDIA_TYPE);
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 out.next = NULL;
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
342 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
343
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
344 return ngx_http_image_send(r, ctx, &out);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
345
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
346 case NGX_HTTP_IMAGE_PASS:
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
347
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
348 return ngx_http_next_body_filter(r, in);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
349
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350 default: /* NGX_HTTP_IMAGE_DONE */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
351
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
352 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
353
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
354 /* 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
355 return (rc == NGX_OK) ? NGX_ERROR : rc;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 }
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
357 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
358
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
359
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
360 static ngx_int_t
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
361 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
362 ngx_chain_t *in)
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
363 {
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
364 ngx_int_t rc;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
365
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
366 rc = ngx_http_next_header_filter(r);
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 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
369 return NGX_ERROR;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
370 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
371
2819
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
372 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
373
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
374 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
375 /* 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
376 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
377 }
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
378
43fe53832da7 handle big responses for "size" and "test" image_filters
Igor Sysoev <igor@sysoev.ru>
parents: 2795
diff changeset
379 return rc;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
380 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
381
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
382
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 static ngx_uint_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
384 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
385 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
386 u_char *p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
387
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
388 p = in->buf->pos;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
389
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
390 if (in->buf->last - p < 16) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
391 return NGX_HTTP_IMAGE_NONE;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
392 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
393
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
394 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
395 "image filter: \"%c%c\"", p[0], p[1]);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
396
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
397 if (p[0] == 0xff && p[1] == 0xd8) {
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 /* JPEG */
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 return NGX_HTTP_IMAGE_JPEG;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
402
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
403 } else if (p[0] == 'G' && p[1] == 'I' && p[2] == 'F' && p[3] == '8'
2943
5da043342fe4 merge r2919:
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
404 && p[5] == 'a')
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
405 {
2943
5da043342fe4 merge r2919:
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
406 if (p[4] == '9' || p[4] == '7') {
5da043342fe4 merge r2919:
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
407 /* GIF */
5da043342fe4 merge r2919:
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
408 return NGX_HTTP_IMAGE_GIF;
5da043342fe4 merge r2919:
Igor Sysoev <igor@sysoev.ru>
parents: 2882
diff changeset
409 }
2788
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 } 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
412 && 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
413 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
414 /* PNG */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
415
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
416 return NGX_HTTP_IMAGE_PNG;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
417 }
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_NONE;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
422
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
423 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
424 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
425 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
426 u_char *p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
427 size_t size, rest;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
428 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
429 ngx_chain_t *cl;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
430 ngx_http_image_filter_ctx_t *ctx;
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 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
433
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
434 if (ctx->image == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
435 ctx->image = ngx_palloc(r->pool, ctx->length);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
436 if (ctx->image == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
437 return NGX_ERROR;
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 ctx->last = ctx->image;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
441 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
442
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
443 p = ctx->last;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
444
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
445 for (cl = in; cl; cl = cl->next) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
446
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
447 b = cl->buf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
448 size = b->last - b->pos;
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 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
451 "image buf: %uz", size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
452
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
453 rest = ctx->image + ctx->length - p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
454 size = (rest < size) ? rest : size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
455
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
456 p = ngx_cpymem(p, b->pos, size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
457 b->pos += size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
458
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
459 if (b->last_buf) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
460 ctx->last = p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
461 return NGX_OK;
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 }
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 ctx->last = p;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
466 r->connection->buffered |= NGX_HTTP_IMAGE_BUFFERED;
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 return NGX_AGAIN;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
469 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
470
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
471
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
472 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
473 ngx_http_image_process(ngx_http_request_t *r)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
474 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
475 ngx_int_t rc;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
476 ngx_http_image_filter_ctx_t *ctx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
477 ngx_http_image_filter_conf_t *conf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
478
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
479 r->connection->buffered &= ~NGX_HTTP_IMAGE_BUFFERED;
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 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
482
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
483 rc = ngx_http_image_size(r, ctx);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
484
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
485 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
486
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
487 if (conf->filter == NGX_HTTP_IMAGE_SIZE) {
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
488 return ngx_http_image_json(r, rc == NGX_OK ? ctx : NULL);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
489 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
490
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
491 ctx->max_width = ngx_http_image_filter_get_value(r, conf->wcv, conf->width);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
492 if (ctx->max_width == 0) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
493 return NULL;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
494 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
495
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
496 ctx->max_height = ngx_http_image_filter_get_value(r, conf->hcv,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
497 conf->height);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
498 if (ctx->max_height == 0) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
499 return NULL;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
500 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
501
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
502 if (rc == NGX_OK
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
503 && ctx->width <= ctx->max_width
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
504 && ctx->height <= ctx->max_height)
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
505 {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
506 return ngx_http_image_asis(r, ctx);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
507 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
508
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
509 return ngx_http_image_resize(r, ctx);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
510 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
511
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
512
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
513 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
514 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
515 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
516 size_t len;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
517 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
518
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
519 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
520 if (b == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
521 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
522 }
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 b->memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
525 b->last_buf = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
526
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
527 ngx_http_clean_header(r);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
528
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
529 r->headers_out.status = NGX_HTTP_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
530 r->headers_out.content_type.len = sizeof("text/plain") - 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
531 r->headers_out.content_type.data = (u_char *) "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
532 r->headers_out.content_type_lowcase = NULL;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
533
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
534 if (ctx == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
535 b->pos = (u_char *) "{}" CRLF;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
536 b->last = b->pos + sizeof("{}" CRLF) - 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
537
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
538 ngx_http_image_length(r, b);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
539
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
540 return b;
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 len = sizeof("{ \"img\" : "
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
544 "{ \"width\": , \"height\": , \"type\": \"jpeg\" } }" CRLF) - 1
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
545 + 2 * NGX_SIZE_T_LEN;
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 b->pos = ngx_pnalloc(r->pool, len);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
548 if (b->pos == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
549 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
550 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
551
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
552 b->last = ngx_sprintf(b->pos,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
553 "{ \"img\" : "
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
554 "{ \"width\": %uz,"
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
555 " \"height\": %uz,"
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
556 " \"type\": \"%s\" } }" CRLF,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
557 ctx->width, ctx->height,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
558 ngx_http_image_types[ctx->type - 1].data + 6);
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 ngx_http_image_length(r, b);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
561
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
562 return b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
563 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
564
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
565
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
566 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
567 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
568 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
569 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
570
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
571 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
572 if (b == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
573 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
574 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
575
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
576 b->pos = ctx->image;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
577 b->last = ctx->last;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
578 b->memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
579 b->last_buf = 1;
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 ngx_http_image_length(r, b);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
582
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
583 return b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
584 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
585
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
586
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
587 static void
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
588 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
589 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
590 r->headers_out.content_length_n = b->last - b->pos;
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 if (r->headers_out.content_length) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
593 r->headers_out.content_length->hash = 0;
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 r->headers_out.content_length = NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
597 }
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
600 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
601 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
602 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
603 u_char *p, *last;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
604 ngx_uint_t width, height;
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 p = ctx->image;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
607
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
608 switch (ctx->type) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
609
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
610 case NGX_HTTP_IMAGE_JPEG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
611
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
612 p += 2;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
613 last = ctx->image + ctx->length - 10;
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 while (p < last) {
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 if (p[0] == 0xff && p[1] != 0xff) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
618
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
619 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
620 "JPEG: %02xd %02xd", *p, *(p + 1));
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 p++;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
623
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
624 if (*p == 0xc0 || *p == 0xc1 || *p == 0xc2 || *p == 0xc3
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
625 || *p == 0xc9 || *p == 0xca || *p == 0xcb)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
626 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
627 goto found;
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 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
631 "JPEG: %02xd %02xd", p[1], p[2]);
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 p += p[1] * 256 + p[2];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
634
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
635 continue;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
638 p++;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
639 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
640
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
641 return NGX_DECLINED;
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 found:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
644
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
645 width = p[6] * 256 + p[7];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
646 height = p[4] * 256 + p[5];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
647
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
648 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
649
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
650 case NGX_HTTP_IMAGE_GIF:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
651
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
652 if (ctx->length < 10) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
653 return NGX_DECLINED;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
654 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
655
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
656 width = p[7] * 256 + p[6];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
657 height = p[9] * 256 + p[8];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
658
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
659 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
660
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
661 case NGX_HTTP_IMAGE_PNG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
662
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
663 if (ctx->length < 24) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
664 return NGX_DECLINED;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
667 width = p[18] * 256 + p[19];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
668 height = p[22] * 256 + p[23];
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
669
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
670 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
671
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
672 default:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
673
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
674 return NGX_DECLINED;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
675 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
676
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
677 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
678 "image size: %d x %d", width, height);
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 ctx->width = width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
681 ctx->height = height;
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 return NGX_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
684 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
685
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
686
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
687 static ngx_buf_t *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
688 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
689 {
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
690 int sx, sy, dx, dy, ox, oy, size,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
691 colors, palette, transparent,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
692 red, green, blue;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
693 u_char *out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
694 ngx_buf_t *b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
695 ngx_uint_t resize;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
696 gdImagePtr src, dst;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
697 ngx_pool_cleanup_t *cln;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
698 ngx_http_image_filter_conf_t *conf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
699
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
700 src = ngx_http_image_source(r, ctx);
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 if (src == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
703 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
704 }
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 sx = gdImageSX(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
707 sy = gdImageSY(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
708
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
709 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
710
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
711 if ((ngx_uint_t) sx <= ctx->max_width
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
712 && (ngx_uint_t) sy <= ctx->max_height)
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
713 {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
714 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
715 return ngx_http_image_asis(r, ctx);
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
718 colors = gdImageColorsTotal(src);
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
719
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
720 if (colors && conf->transparency) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
721 transparent = gdImageGetTransparent(src);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
722
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
723 if (transparent != -1) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
724 palette = colors;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
725 red = gdImageRed(src, transparent);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
726 green = gdImageGreen(src, transparent);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
727 blue = gdImageBlue(src, transparent);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
728
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
729 goto transparent;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
730 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
731 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
732
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
733 palette = 0;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
734 transparent = -1;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
735 red = 0;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
736 green = 0;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
737 blue = 0;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
738
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
739 transparent:
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
740
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
741 gdImageColorTransparent(src, -1);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
742
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
743 dx = sx;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
744 dy = sy;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
745
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
746 if (conf->filter == NGX_HTTP_IMAGE_RESIZE) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
747
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
748 if ((ngx_uint_t) dx > ctx->max_width) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
749 dy = dy * ctx->max_width / dx;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
750 dy = dy ? dy : 1;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
751 dx = ctx->max_width;
2788
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
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
754 if ((ngx_uint_t) dy > ctx->max_height) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
755 dx = dx * ctx->max_height / dy;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
756 dx = dx ? dx : 1;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
757 dy = ctx->max_height;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
758 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
759
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
760 resize = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
761
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
762 } else { /* NGX_HTTP_IMAGE_CROP */
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
763
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
764 resize = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
765
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
766 if ((ngx_uint_t) (dx * 100 / dy)
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
767 < ctx->max_width * 100 / ctx->max_height)
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
768 {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
769 if ((ngx_uint_t) dx > ctx->max_width) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
770 dy = dy * ctx->max_width / dx;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
771 dy = dy ? dy : 1;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
772 dx = ctx->max_width;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
773 resize = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
774 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
775
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
776 } else {
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
777 if ((ngx_uint_t) dy > ctx->max_height) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
778 dx = dx * ctx->max_height / dy;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
779 dx = dx ? dx : 1;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
780 dy = ctx->max_height;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
781 resize = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
782 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
783 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
784 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
785
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
786 if (resize) {
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
787 dst = ngx_http_image_new(r, dx, dy, palette);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
788 if (dst == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
789 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
790 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
791 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
792
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
793 if (colors == 0) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
794 gdImageSaveAlpha(dst, 1);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
795 gdImageAlphaBlending(dst, 0);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
796 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
797
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
798 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
799
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
800 if (colors) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
801 gdImageTrueColorToPalette(dst, 1, 256);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
802 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
803
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
804 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
805
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
806 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
807 dst = src;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
810 if (conf->filter == NGX_HTTP_IMAGE_CROP) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
811
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
812 src = dst;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
813
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
814 if ((ngx_uint_t) dx > ctx->max_width) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
815 ox = dx - ctx->max_width;
2788
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 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
818 ox = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
819 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
820
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
821 if ((ngx_uint_t) dy > ctx->max_height) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
822 oy = dy - ctx->max_height;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
823
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
824 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
825 oy = 0;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
826 }
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 if (ox || oy) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
829
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
830 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
831
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
832 if (dst == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
833 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
834 return NULL;
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 ox /= 2;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
838 oy /= 2;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
839
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
840 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
841 "image crop: %d x %d @ %d x %d",
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
842 dx, dy, ox, oy);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
843
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
844 if (colors == 0) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
845 gdImageSaveAlpha(dst, 1);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
846 gdImageAlphaBlending(dst, 0);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
847 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
848
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
849 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
850
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
851 if (colors) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
852 gdImageTrueColorToPalette(dst, 1, 256);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
853 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
854
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
855 gdImageDestroy(src);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
856 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
857 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
858
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
859 if (transparent != -1 && colors) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
860 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue));
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
861 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
862
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
863 out = ngx_http_image_out(r, ctx->type, dst, &size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
864
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
865 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
866 "image: %d x %d %d", sx, sy, colors);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
867
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
868 gdImageDestroy(dst);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
869 ngx_pfree(r->pool, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
870
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
871 if (out == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
872 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
873 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
874
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
875 cln = ngx_pool_cleanup_add(r->pool, 0);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
876 if (cln == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
877 gdFree(out);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
878 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
879 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
880
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
881 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
882 if (b == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
883 gdFree(out);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
884 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
885 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
886
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
887 cln->handler = ngx_http_image_cleanup;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
888 cln->data = out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
889
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
890 b->pos = out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
891 b->last = out + size;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
892 b->memory = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
893 b->last_buf = 1;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
894
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
895 ngx_http_image_length(r, b);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
896
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
897 return b;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
898 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
899
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
900
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
901 static gdImagePtr
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
902 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
903 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
904 char *failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
905 gdImagePtr img;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
906
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
907 img = NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
908
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
909 switch (ctx->type) {
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 case NGX_HTTP_IMAGE_JPEG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
912 img = gdImageCreateFromJpegPtr(ctx->length, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
913 failed = "gdImageCreateFromJpegPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
914 break;
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 case NGX_HTTP_IMAGE_GIF:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
917 img = gdImageCreateFromGifPtr(ctx->length, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
918 failed = "gdImageCreateFromGifPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
919 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
920
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
921 case NGX_HTTP_IMAGE_PNG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
922 img = gdImageCreateFromPngPtr(ctx->length, ctx->image);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
923 failed = "gdImageCreateFromPngPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
924 break;
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 default:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
927 failed = "unknown image type";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
928 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
929 }
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 (img == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
932 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
933 }
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 return img;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
936 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
937
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
938
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
939 static gdImagePtr
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
940 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
941 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
942 gdImagePtr img;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
943
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
944 if (colors == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
945 img = gdImageCreateTrueColor(w, h);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
946
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
947 if (img == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
948 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
949 "gdImageCreateTrueColor() failed");
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
950 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
951 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
952
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
953 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
954 img = gdImageCreate(w, h);
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 if (img == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
957 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
958 "gdImageCreate() failed");
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
959 return NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
960 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
961 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
962
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
963 return img;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
964 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
965
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
966
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
967 static u_char *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
968 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
969 int *size)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
970 {
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
971 char *failed;
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
972 u_char *out;
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
973 ngx_http_image_filter_conf_t *conf;
2788
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 out = NULL;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
976
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
977 switch (type) {
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 case NGX_HTTP_IMAGE_JPEG:
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
980 conf = ngx_http_get_module_loc_conf(r, ngx_http_image_filter_module);
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
981 out = gdImageJpegPtr(img, size, conf->jpeg_quality);
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
982 failed = "gdImageJpegPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
983 break;
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 case NGX_HTTP_IMAGE_GIF:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
986 out = gdImageGifPtr(img, size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
987 failed = "gdImageGifPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
988 break;
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 case NGX_HTTP_IMAGE_PNG:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
991 out = gdImagePngPtr(img, size);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
992 failed = "gdImagePngPtr() failed";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
993 break;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
994
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
995 default:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
996 failed = "unknown image type";
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
997 break;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1000 if (out == NULL) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1001 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
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 return out;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1005 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1006
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 static void
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1009 ngx_http_image_cleanup(void *data)
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 gdFree(data);
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1014
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1015 static ngx_uint_t
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1016 ngx_http_image_filter_get_value(ngx_http_request_t *r,
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1017 ngx_http_complex_value_t *cv, ngx_uint_t v)
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1018 {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1019 ngx_str_t val;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1020
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1021 if (cv == NULL) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1022 return v;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1023 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1024
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1025 if (ngx_http_complex_value(r, cv, &val) != NGX_OK) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1026 return 0;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1027 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1028
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1029 return ngx_http_image_filter_value(&val);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1030 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1031
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1032
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1033 static ngx_uint_t
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1034 ngx_http_image_filter_value(ngx_str_t *value)
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1035 {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1036 ngx_int_t n;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1037
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1038 if (value->len == 1 && value->data[0] == '-') {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1039 return (ngx_uint_t) -1;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1040 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1041
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1042 n = ngx_atoi(value->data, value->len);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1043
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1044 if (n > 0) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1045 return (ngx_uint_t) n;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1046 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1047
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1048 return 0;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1049 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1050
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1051
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1052 static void *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1053 ngx_http_image_filter_create_conf(ngx_conf_t *cf)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1054 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1055 ngx_http_image_filter_conf_t *conf;
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 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
1058 if (conf == NULL) {
3237
2efa8d2fcde1 merge r2903, r2911, r2912, r3002:
Igor Sysoev <igor@sysoev.ru>
parents: 2943
diff changeset
1059 return NULL;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1060 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1061
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1062 conf->filter = NGX_CONF_UNSET_UINT;
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1063 conf->jpeg_quality = NGX_CONF_UNSET;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1064 conf->transparency = NGX_CONF_UNSET;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1065 conf->buffer_size = NGX_CONF_UNSET_SIZE;
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 conf;
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 char *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1072 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
1073 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1074 ngx_http_image_filter_conf_t *prev = parent;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1075 ngx_http_image_filter_conf_t *conf = child;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1076
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1077 if (conf->filter == NGX_CONF_UNSET_UINT) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1078
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1079 if (prev->filter == NGX_CONF_UNSET_UINT) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1080 conf->filter = NGX_HTTP_IMAGE_OFF;
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 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1083 conf->filter = prev->filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1084 conf->width = prev->width;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1085 conf->height = prev->height;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1086 conf->wcv = prev->wcv;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1087 conf->hcv = prev->hcv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1088 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1089 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1090
2848
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1091 /* 75 is libjpeg default quality */
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1092 ngx_conf_merge_value(conf->jpeg_quality, prev->jpeg_quality, 75);
0d8941f2b0ee image_filter_jpeg_quality
Igor Sysoev <igor@sysoev.ru>
parents: 2834
diff changeset
1093
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1094 ngx_conf_merge_value(conf->transparency, prev->transparency, 1);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1095
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1096 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
1097 1 * 1024 * 1024);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1098
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1099 return NGX_CONF_OK;
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
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1102
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1103 static char *
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1104 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
1105 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1106 ngx_http_image_filter_conf_t *imcf = conf;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1107
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1108 ngx_str_t *value;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1109 ngx_int_t n;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1110 ngx_uint_t i;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1111 ngx_http_complex_value_t cv;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1112 ngx_http_compile_complex_value_t ccv;
2788
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 value = cf->args->elts;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1115
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1116 i = 1;
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 if (cf->args->nelts == 2) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1119 if (ngx_strcmp(value[i].data, "off") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1120 imcf->filter = NGX_HTTP_IMAGE_OFF;
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 } else if (ngx_strcmp(value[i].data, "test") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1123 imcf->filter = NGX_HTTP_IMAGE_TEST;
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 } else if (ngx_strcmp(value[i].data, "size") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1126 imcf->filter = NGX_HTTP_IMAGE_SIZE;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1127
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1128 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1129 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1130 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1131
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1132 return NGX_CONF_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1133 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1134
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1135 if (ngx_strcmp(value[i].data, "resize") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1136 imcf->filter = NGX_HTTP_IMAGE_RESIZE;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1137
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1138 } else if (ngx_strcmp(value[i].data, "crop") == 0) {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1139 imcf->filter = NGX_HTTP_IMAGE_CROP;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1140
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1141 } else {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1142 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1143 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1144
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1145 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1146
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1147 ccv.cf = cf;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1148 ccv.value = &value[++i];
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1149 ccv.complex_value = &cv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1150
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1151 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1152 return NGX_CONF_ERROR;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1153 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1154
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1155 if (cv.lengths == NULL) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1156 n = ngx_http_image_filter_value(&value[i]);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1157
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1158 if (n == 0) {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1159 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1160 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1161
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1162 imcf->width = (ngx_uint_t) n;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1163
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1164 } else {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1165 imcf->wcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1166 if (imcf->wcv == NULL) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1167 return NGX_CONF_ERROR;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1168 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1169
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1170 *imcf->wcv = cv;
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
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1173 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1174
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1175 ccv.cf = cf;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1176 ccv.value = &value[++i];
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1177 ccv.complex_value = &cv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1178
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1179 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1180 return NGX_CONF_ERROR;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1181 }
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1182
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1183 if (cv.lengths == NULL) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1184 n = ngx_http_image_filter_value(&value[i]);
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1185
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1186 if (n == 0) {
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1187 goto failed;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1188 }
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 imcf->height = (ngx_uint_t) n;
3244
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1191
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1192 } else {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1193 imcf->hcv = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1194 if (imcf->hcv == NULL) {
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1195 return NGX_CONF_ERROR;
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1196 }
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1197
8b2d478de54b merge r2999, r3118, r3134, r3135:
Igor Sysoev <igor@sysoev.ru>
parents: 3237
diff changeset
1198 *imcf->hcv = cv;
2788
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1199 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1200
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1201 return NGX_CONF_OK;
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 failed:
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1204
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1205 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
1206 &value[i]);
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1207
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1208 return NGX_CONF_ERROR;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1209 }
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1210
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1211
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1212 static ngx_int_t
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1213 ngx_http_image_filter_init(ngx_conf_t *cf)
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1214 {
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1215 ngx_http_next_header_filter = ngx_http_top_header_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1216 ngx_http_top_header_filter = ngx_http_image_header_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1217
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1218 ngx_http_next_body_filter = ngx_http_top_body_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1219 ngx_http_top_body_filter = ngx_http_image_body_filter;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1220
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1221 return NGX_OK;
a16ec9e1b4d1 ngx_http_image_filter_module
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
1222 }