Mercurial > hg > nginx
comparison src/http/modules/ngx_http_image_filter_module.c @ 3117:e2a510ac53db
fix transparency in GIF
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Sat, 12 Sep 2009 09:46:28 +0000 |
parents | fa8503fd3647 |
children | 28a6aa24b453 |
comparison
equal
deleted
inserted
replaced
3116:98e288c6dac3 | 3117:e2a510ac53db |
---|---|
677 | 677 |
678 static ngx_buf_t * | 678 static ngx_buf_t * |
679 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) | 679 ngx_http_image_resize(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx) |
680 { | 680 { |
681 int sx, sy, dx, dy, ox, oy, | 681 int sx, sy, dx, dy, ox, oy, |
682 colors, transparent, size; | 682 colors, transparent, red, green, blue, size; |
683 u_char *out; | 683 u_char *out; |
684 ngx_buf_t *b; | 684 ngx_buf_t *b; |
685 ngx_uint_t resize; | 685 ngx_uint_t resize; |
686 gdImagePtr src, dst; | 686 gdImagePtr src, dst; |
687 ngx_pool_cleanup_t *cln; | 687 ngx_pool_cleanup_t *cln; |
705 return ngx_http_image_asis(r, ctx); | 705 return ngx_http_image_asis(r, ctx); |
706 } | 706 } |
707 | 707 |
708 colors = gdImageColorsTotal(src); | 708 colors = gdImageColorsTotal(src); |
709 transparent = gdImageGetTransparent(src); | 709 transparent = gdImageGetTransparent(src); |
710 | |
711 if (transparent != -1 && colors) { | |
712 red = gdImageRed(src, transparent); | |
713 green = gdImageGreen(src, transparent); | |
714 blue = gdImageBlue(src, transparent); | |
715 gdImageColorTransparent(src, -1); | |
716 | |
717 } else { | |
718 red = 0; green = 0; blue = 0; | |
719 } | |
710 | 720 |
711 dx = sx; | 721 dx = sx; |
712 dy = sy; | 722 dy = sy; |
713 | 723 |
714 if (conf->filter == NGX_HTTP_IMAGE_RESIZE) { | 724 if (conf->filter == NGX_HTTP_IMAGE_RESIZE) { |
804 | 814 |
805 gdImageDestroy(src); | 815 gdImageDestroy(src); |
806 } | 816 } |
807 } | 817 } |
808 | 818 |
809 gdImageColorTransparent(dst, transparent); | 819 if (transparent != -1 && colors) { |
820 gdImageColorTransparent(dst, gdImageColorExact(dst, red, green, blue)); | |
821 } | |
810 | 822 |
811 out = ngx_http_image_out(r, ctx->type, dst, &size); | 823 out = ngx_http_image_out(r, ctx->type, dst, &size); |
812 | 824 |
813 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 825 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
814 "image: %d x %d %d", sx, sy, colors); | 826 "image: %d x %d %d", sx, sy, colors); |