Mercurial > hg > nginx
comparison src/http/modules/ngx_http_image_filter_module.c @ 3910:750fb808aa15
gdImageCopyRotated() may images of even height or width
patch by Adam Bocim
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 10 May 2011 12:04:57 +0000 |
parents | ea712f4dc030 |
children | 01a7e78ff5a1 d0e52213406f |
comparison
equal
deleted
inserted
replaced
3909:0daede16d68b | 3910:750fb808aa15 |
---|---|
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 |