comparison src/http/modules/ngx_http_image_filter_module.c @ 624:d4da38525468 NGINX_1_0_2

nginx 1.0.2 *) Feature: now shared zones and caches use POSIX semaphores. *) Bugfix: in the "rotate" parameter of the "image_filter" directive. Thanks to Adam Bocim. *) Bugfix: nginx could not be built on Solaris; the bug had appeared in 1.0.1.
author Igor Sysoev <http://sysoev.ru>
date Tue, 10 May 2011 00:00:00 +0400
parents b4dcae568a2a
children f200748c0ac8
comparison
equal deleted inserted replaced
623:9b9e61f1b500 624:d4da38525468
721 721
722 722
723 static ngx_buf_t * 723 static ngx_buf_t *
724 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) 724 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
725 { 725 {
726 int sx, sy, dx, dy, ox, oy, size, 726 int sx, sy, dx, dy, ox, oy, ax, ay, size,
727 colors, palette, transparent, 727 colors, palette, transparent,
728 red, green, blue, t; 728 red, green, blue, t;
729 u_char *out; 729 u_char *out;
730 ngx_buf_t *b; 730 ngx_buf_t *b;
731 ngx_uint_t resize; 731 ngx_uint_t resize;
850 } 850 }
851 851
852 if (ctx->angle) { 852 if (ctx->angle) {
853 src = dst; 853 src = dst;
854 854
855 ax = (dx % 2 == 0) ? 1 : 0;
856 ay = (dy % 2 == 0) ? 1 : 0;
857
855 switch (ctx->angle) { 858 switch (ctx->angle) {
856 859
857 case 90: 860 case 90:
858 case 270: 861 case 270:
859 dst = ngx_http_image_new(r, dy, dx, palette); 862 dst = ngx_http_image_new(r, dy, dx, palette);
860 if (dst == NULL) { 863 if (dst == NULL) {
861 gdImageDestroy(src); 864 gdImageDestroy(src);
862 return NULL; 865 return NULL;
863 } 866 }
864 gdImageCopyRotated(dst, src, dy/2, dx/2, 0, 0, dx, dy, ctx->angle); 867 if (ctx->angle == 90) {
868 ox = dy / 2 + ay;
869 oy = dx / 2 - ax;
870
871 } else {
872 ox = dy / 2 - ay;
873 oy = dx / 2 + ax;
874 }
875
876 gdImageCopyRotated(dst, src, ox, oy, 0, 0,
877 dx + ax, dy + ay, ctx->angle);
865 gdImageDestroy(src); 878 gdImageDestroy(src);
866 879
867 t = dx; 880 t = dx;
868 dx = dy; 881 dx = dy;
869 dy = t; 882 dy = t;
873 dst = ngx_http_image_new(r, dx, dy, palette); 886 dst = ngx_http_image_new(r, dx, dy, palette);
874 if (dst == NULL) { 887 if (dst == NULL) {
875 gdImageDestroy(src); 888 gdImageDestroy(src);
876 return NULL; 889 return NULL;
877 } 890 }
878 gdImageCopyRotated(dst, src, dx/2, dy/2, 0, 0, dx, dy, ctx->angle); 891 gdImageCopyRotated(dst, src, dx / 2 - ax, dy / 2 - ay, 0, 0,
892 dx + ax, dy + ay, ctx->angle);
879 gdImageDestroy(src); 893 gdImageDestroy(src);
880 break; 894 break;
881 } 895 }
882 } 896 }
883 897