annotate src/http/modules/ngx_http_image_filter_module.c @ 7732:59e1c73fe02b

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