Skip to content

Commit

Permalink
Update ngx_http_image_module.c
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Jul 17, 2014
1 parent 35e577b commit 398b92e
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions ngx_http_image_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static ngx_uint_t ngx_http_image_value(ngx_str_t *value);
char * ngx_conf_set_number_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char * ngx_conf_set_string_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t output(ngx_http_request_t *r,void *conf,ngx_str_t type);
static void gd_cleanup(void *conf);//清除GD对象
static void make_thumb(void *conf);//创建GD对象缩略图,缩略图在此函数中已经处理好,但没有写入到文件
static void water_mark(void *conf);//给图片打上水印
static void thumb_to_string(void *conf);//GD对象数据转换为二进制字符串
Expand Down Expand Up @@ -397,21 +398,6 @@ static ngx_int_t ngx_http_image_handler(ngx_http_request_t *r)
{
write_img(conf);//保存图片缩略图到文件
}
if(conf->src_im != NULL){
gdImageDestroy(conf->src_im);
}
if(conf->dst_im != NULL)
{
gdImageDestroy(conf->dst_im);
}
if(conf->water_im != NULL)
{
gdImageDestroy(conf->water_im);
}
if(conf->w_margin > 0 && conf->w_im != NULL)
{
gdImageDestroy(conf->w_im);//释放补白边的对象
}
if(conf->image_output == 1)
{
return output(r,conf,ngx_http_image_types[conf->dest_type]);
Expand Down Expand Up @@ -505,12 +491,15 @@ ngx_http_image(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

static ngx_int_t output(ngx_http_request_t *r,void *conf,ngx_str_t type)
{
ngx_int_t status;
ngx_image_conf_t *info = conf;
ngx_http_complex_value_t cv;
ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
cv.value.len = info->img_size;
cv.value.data = (u_char *)info->img_data;
return ngx_http_send_response(r, NGX_HTTP_OK, &type, &cv);
status = ngx_http_send_response(r, NGX_HTTP_OK, &type, &cv);
gd_cleanup(info);
return status;
}

static void thumb_to_string(void *conf)
Expand All @@ -533,6 +522,27 @@ static void thumb_to_string(void *conf)
}
}

static void gd_cleanup(void *conf){
ngx_image_conf_t *info = conf;
if(info->src_im != NULL){
gdImageDestroy(info->src_im);
}
if(info->dst_im != NULL)
{
gdImageDestroy(info->dst_im);
}
if(info->water_im != NULL){
gdImageDestroy(info->water_im);
}
if(info->w_margin > 0 && info->w_im != NULL)
{
gdImageDestroy(info->w_im);//释放补白边的对象
}
if(info->img_data != NULL){
gdFree(info->img_data);
}
}

static void make_thumb(void *conf)
{
int colors = 0;
Expand Down Expand Up @@ -1008,6 +1018,7 @@ static void write_img(void * conf)
fwrite(info->img_data,sizeof(char),info->img_size,fp);
fclose(fp);
}
gd_cleanup(info);
}


Expand Down Expand Up @@ -1208,5 +1219,3 @@ static void download(void * conf)
}
free(info->request_source);
}


0 comments on commit 398b92e

Please sign in to comment.