Skip to content

Add support bitmap--Update ngx_http_image_filter_module.c #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions ngx_http_image_filter_module.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Copyright (C) Igor Sysoev
* Copyright (C) Nginx, Inc.
Expand Down Expand Up @@ -31,6 +30,7 @@
#define NGX_HTTP_IMAGE_JPEG 1
#define NGX_HTTP_IMAGE_GIF 2
#define NGX_HTTP_IMAGE_PNG 3
#define NGX_HTTP_IMAGE_BMP 4

#define NGX_HTTP_IMAGE_OFFSET_CENTER 0
#define NGX_HTTP_IMAGE_OFFSET_LEFT 1
Expand Down Expand Up @@ -212,7 +212,8 @@ static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
static ngx_str_t ngx_http_image_types[] = {
ngx_string("image/jpeg"),
ngx_string("image/gif"),
ngx_string("image/png")
ngx_string("image/png"),
ngx_string("image/bmp")
};


Expand Down Expand Up @@ -453,6 +454,10 @@ ngx_http_image_test(ngx_http_request_t *r, ngx_chain_t *in)
/* PNG */

return NGX_HTTP_IMAGE_PNG;
} else if (p[0] == 'B' && p[1] == 'M')
{
/* BMP */
return NGX_HTTP_IMAGE_BMP;
}

return NGX_HTTP_IMAGE_NONE;
Expand Down Expand Up @@ -736,6 +741,16 @@ ngx_http_image_size(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
height = p[22] * 256 + p[23];

break;

case NGX_HTTP_IMAGE_BMP:
if (ctx->length < 26) {
return NGX_DECLINED;
}

width = p[19] * 256 + p[18];
height = p[23] * 256 + p[22];

break;

default:

Expand Down Expand Up @@ -1062,6 +1077,11 @@ ngx_http_image_source(ngx_http_request_t *r, ngx_http_image_filter_ctx_t *ctx)
img = gdImageCreateFromPngPtr(ctx->length, ctx->image);
failed = "gdImageCreateFromPngPtr() failed";
break;

case NGX_HTTP_IMAGE_BMP:
img = gdImageCreateFromBmpPtr(ctx->length, ctx->image);
failed = "gdImageCreateFromBmpPtr() failed";
break;

default:
failed = "unknown image type";
Expand Down Expand Up @@ -1138,6 +1158,11 @@ ngx_http_image_out(ngx_http_request_t *r, ngx_uint_t type, gdImagePtr img,
out = gdImagePngPtr(img, size);
failed = "gdImagePngPtr() failed";
break;

case NGX_HTTP_IMAGE_BMP:
out = gdImageBmpPtr(img, size, -1);
failed = "gdImageBmpPtr() failed";
break;

default:
failed = "unknown image type";
Expand Down