void test_wand(void) { MagickWand *magick_wand = NULL; MagickWand *c_wand = NULL; DrawingWand *d_wand = NULL; PixelWand *p_wand = NULL; // Used for text effect #3 double dargs[1] = {120.}; // Used for text effect #5 double d_args[8] = { -0.02,0.0, 0.0,1.02, 0.0,0.0, -0.5,1.9 }; MagickWandGenesis(); // Text effect 1 - shadow effect using MagickShadowImage // This is derived from Anthony's Soft Shadow effect // convert -size 300x100 xc:none -font Candice -pointsize 72 \ // -fill white -stroke black -annotate +25+65 'Anthony' \ // \( +clone -background navy -shadow 70x4+5+5 \) +swap \ // -background lightblue -flatten -trim +repage font_shadow_soft.jpg //NOTE - if an image has a transparent background, adding a border of any colour other // than "none" will remove all the transparency and replace it with the border's colour magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); PixelSetColor(p_wand,"none"); // Create a new transparent image MagickNewImage(magick_wand,350,100,p_wand); // Set up a 72 point white font PixelSetColor(p_wand,"white"); DrawSetFillColor(d_wand,p_wand); DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Add a black outline to the text PixelSetColor(p_wand,"black"); DrawSetStrokeColor(d_wand,p_wand); // Turn antialias on - not sure this makes a difference DrawSetTextAntialias(d_wand,MagickTrue); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); // Trim the image down to include only the text MagickTrimImage(magick_wand,0); // equivalent to the command line +repage MagickResetImagePage(magick_wand,""); // Make a copy of the text image c_wand = CloneMagickWand(magick_wand); // Set the background colour to blue for the shadow PixelSetColor(p_wand,"blue"); MagickSetImageBackgroundColor(magick_wand,p_wand); // Opacity is a real number indicating (apparently) percentage MagickShadowImage(magick_wand,70,4,5,5); // Composite the text on top of the shadow MagickCompositeImage(magick_wand,c_wand,OverCompositeOp,5,5); if(c_wand)c_wand = DestroyMagickWand(c_wand); c_wand = NewMagickWand(); // Create a new image the same size as the text image and put a solid colour // as its background PixelSetColor(p_wand,"rgb(125,215,255)"); MagickNewImage(c_wand,MagickGetImageWidth(magick_wand),MagickGetImageHeight(magick_wand),p_wand); // Now composite the shadowed text over the plain background MagickCompositeImage(c_wand,magick_wand,OverCompositeOp,0,0); // and write the result MagickWriteImage(c_wand,"text_shadow.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(c_wand)c_wand = DestroyMagickWand(c_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 2 - tiled text using the builtin checkerboard pattern // Anthony's Tiled Font effect // convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \ // -tile pattern:checkerboard -annotate +28+68 'Anthony' \ // font_tile.jpg magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); set_tile_pattern(d_wand,"#check","pattern:checkerboard"); PixelSetColor(p_wand,"lightblue"); // Create a new transparent image MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,28,68,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); // Trim the image MagickTrimImage(magick_wand,0); // Add a transparent border PixelSetColor(p_wand,"lightblue"); MagickBorderImage(magick_wand,p_wand,5,5); // and write it MagickWriteImage(magick_wand,"text_pattern.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 3 - arc font (similar to http://www.imagemagick.org/Usage/fonts/#arc) //convert -size 320x100 xc:lightblue -font Candice -pointsize 72 \ // -annotate +25+65 'Anthony' -distort Arc 120 \ // -trim +repage -bordercolor lightblue -border 10 font_arc.jpg magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x100 lightblue canvas PixelSetColor(p_wand,"lightblue"); MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); MagickDistortImage(magick_wand,ArcDistortion,1,dargs,MagickFalse); // Trim the image MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"lightblue"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_arc.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 4 - bevelled font http://www.imagemagick.org/Usage/fonts/#bevel // convert -size 320x100 xc:black -font Candice -pointsize 72 \ // -fill white -annotate +25+65 'Anthony' \ // -shade 140x60 font_beveled.jpg magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x100 canvas PixelSetColor(p_wand,"gray"); MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Set up a 72 point white font PixelSetColor(p_wand,"white"); DrawSetFillColor(d_wand,p_wand); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); // the "gray" parameter must be true to get the effect shown on Anthony's page MagickShadeImage(magick_wand,MagickTrue,140,60); #ifdef COLORIZE PixelSetColor(p_wand,"yellow"); DrawSetFillColor(d_wand,p_wand); cp_wand = NewPixelWand(); PixelSetColor(cp_wand,"gold"); MagickColorizeImage(magick_wand,p_wand,cp_wand); #endif // and write it MagickWriteImage(magick_wand,"text_bevel.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); #ifdef COLORIZE if(cp_wand)cp_wand = DestroyPixelWand(cp_wand); #endif // Text effect 5 and 6 - Plain text and then Barrel distortion // This one uses d_args magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x100 transparent canvas PixelSetColor(p_wand,"none"); MagickNewImage(magick_wand,320,100,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); MagickWriteImage(magick_wand,"text_plain.png"); // Trim the image MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // MagickSetImageMatte(magick_wand,MagickTrue); // MagickSetImageVirtualPixelMethod(magick_wand,TransparentVirtualPixelMethod); // d_args[0] = 0.1;d_args[1] = -0.25;d_args[2] = -0.25; [3] += .1 // The first value should be positive. If it is negative the image is *really* distorted d_args[0] = 0.0; d_args[1] = 0.0; d_args[2] = 0.5; // d_args[3] should normally be chosen such the sum of all 4 values is 1 // so that the result is the same size as the original // You can override the sum with a different value // If the sum is greater than 1 the resulting image will be smaller than the original d_args[3] = 1 - (d_args[0] + d_args[1] + d_args[2]); // Make the result image smaller so that it isn't as likely // to overflow the edges // d_args[3] += 0.1; // 0.0,0.0,0.5,0.5,0.0,0.0,-0.5,1.9 d_args[3] = 0.5; d_args[4] = 0.0; d_args[5] = 0.0; d_args[6] = -0.5; d_args[7] = 1.9; // DON'T FORGET to set the correct number of arguments here MagickDistortImage(magick_wand,BarrelDistortion,8,d_args,MagickTrue); // MagickResetImagePage(magick_wand,""); // Trim the image again MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_barrel.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 7 - Polar distortion // This one uses d_args[0] magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x200 transparent canvas PixelSetColor(p_wand,"none"); MagickNewImage(magick_wand,320,200,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,25,65,(const unsigned char *)"Magick"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); d_args[0] = 0.0; // DON'T FORGET to set the correct number of arguments here MagickDistortImage(magick_wand,PolarDistortion,1,d_args,MagickTrue); // MagickResetImagePage(magick_wand,""); // Trim the image again MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_polar.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); // Text effect 8 - Shepard's distortion // This one uses d_args[0] magick_wand = NewMagickWand(); d_wand = NewDrawingWand(); p_wand = NewPixelWand(); // Create a 320x200 transparent canvas PixelSetColor(p_wand,"none"); MagickNewImage(magick_wand,640,480,p_wand); // Set up a 72 point font DrawSetFont (d_wand, "Verdana-Bold-Italic" ) ; DrawSetFontSize(d_wand,72); // Now draw the text DrawAnnotation(d_wand,50,240,(const unsigned char *)"Magick Rocks"); // Draw the image on to the magick_wand MagickDrawImage(magick_wand,d_wand); d_args[0] = 150.0; d_args[1] = 190.0; d_args[2] = 100.0; d_args[3] = 290.0; d_args[4] = 500.0; d_args[5] = 200.0; d_args[6] = 430.0; d_args[7] = 130.0; // DON'T FORGET to set the correct number of arguments here MagickDistortImage(magick_wand,ShepardsDistortion,8,d_args,MagickTrue); // Trim the image MagickTrimImage(magick_wand,0); // Add the border PixelSetColor(p_wand,"none"); MagickBorderImage(magick_wand,p_wand,10,10); // and write it MagickWriteImage(magick_wand,"text_shepards.png"); /* Clean up */ if(magick_wand)magick_wand = DestroyMagickWand(magick_wand); if(d_wand)d_wand = DestroyDrawingWand(d_wand); if(p_wand)p_wand = DestroyPixelWand(p_wand); MagickWandTerminus(); }
ngx_int_t ngx_http_small_light_imagemagick_process(ngx_http_request_t *r, ngx_http_small_light_ctx_t *ctx) { ngx_http_small_light_imagemagick_ctx_t *ictx; ngx_http_small_light_image_size_t sz; MagickBooleanType status; int rmprof_flg, progressive_flg, cmyk2rgb_flg; double iw, ih, q; char *unsharp, *sharpen, *blur, *of, *of_orig; MagickWand *trans_wand, *canvas_wand; DrawingWand *border_wand; PixelWand *bg_color, *canvas_color, *border_color; GeometryInfo geo; ngx_fd_t fd; MagickWand *icon_wand; u_char *p, *embedicon; size_t embedicon_path_len, embedicon_len, sled_image_size; ngx_int_t type; u_char jpeg_size_opt[32], crop_geo[128], size_geo[128], embedicon_path[256]; ColorspaceType color_space; #if MagickLibVersion >= 0x690 int autoorient_flg; #endif status = MagickFalse; ictx = (ngx_http_small_light_imagemagick_ctx_t *)ctx->ictx; /* adjust image size */ ngx_http_small_light_calc_image_size(r, ctx, &sz, 10000.0, 10000.0); /* prepare */ if (sz.jpeghint_flg != 0) { p = ngx_snprintf((u_char *)jpeg_size_opt, sizeof(jpeg_size_opt) - 1, "%dx%d", (ngx_int_t)sz.dw, (ngx_int_t)sz.dh); *p = '\0'; ngx_log_error(NGX_LOG_DEBUG, r->connection->log, 0, "jpeg_size_opt:%s", jpeg_size_opt); MagickSetOption(ictx->wand, "jpeg:size", (char *)jpeg_size_opt); } /* load image. */ status = MagickReadImageBlob(ictx->wand, (void *)ictx->image, ictx->image_len); if (status == MagickFalse) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "couldn't read image %s:%d", __FUNCTION__, __LINE__); return NGX_ERROR; } MagickSetFirstIterator(ictx->wand); color_space = MagickGetImageColorspace(ictx->wand); /* remove all profiles */ rmprof_flg = ngx_http_small_light_parse_flag(NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "rmprof")); if (rmprof_flg != 0) { status = MagickProfileImage(ictx->wand, "*", NULL, 0); if (status == MagickFalse) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "couldn't profiling image %s:%d", __FUNCTION__, __LINE__); } } of_orig = MagickGetImageFormat(ictx->wand); status = MagickTrue; #if MagickLibVersion >= 0x690 /* auto-orient */ autoorient_flg = ngx_http_small_light_parse_flag(NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "autoorient")); if (autoorient_flg != 0) { status = MagickAutoOrientImage(ictx->wand); if (status == MagickFalse) { r->err_status = NGX_HTTP_INTERNAL_SERVER_ERROR; DestroyString(of_orig); return NGX_ERROR; } } #endif /* rotate. */ if (sz.angle) { bg_color = NewPixelWand(); PixelSetRed(bg_color, sz.cc.r / 255.0); PixelSetGreen(bg_color, sz.cc.g / 255.0); PixelSetBlue(bg_color, sz.cc.b / 255.0); PixelSetAlpha(bg_color, sz.cc.a / 255.0); switch (sz.angle) { case 90: case 180: case 270: MagickRotateImage(ictx->wand, bg_color, sz.angle); break; default: ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "image not rotated. 'angle'(%ui) must be 90 or 180 or 270. %s:%d", sz.angle, __FUNCTION__, __LINE__); break; } DestroyPixelWand(bg_color); } /* calc size. */ iw = (double)MagickGetImageWidth(ictx->wand); ih = (double)MagickGetImageHeight(ictx->wand); ngx_http_small_light_calc_image_size(r, ctx, &sz, iw, ih); /* pass through. */ if (sz.pt_flg != 0) { ctx->of = ctx->inf; DestroyString(of_orig); return NGX_OK; } /* crop, scale. */ if (sz.scale_flg != 0) { p = ngx_snprintf(crop_geo, sizeof(crop_geo) - 1, "%f!x%f!+%f+%f", sz.sw, sz.sh, sz.sx, sz.sy); *p = '\0'; p = ngx_snprintf(size_geo, sizeof(size_geo) - 1, "%f!x%f!", sz.dw, sz.dh); *p = '\0'; ngx_log_error(NGX_LOG_DEBUG, r->connection->log, 0, "crop_geo:%s", crop_geo); ngx_log_error(NGX_LOG_DEBUG, r->connection->log, 0, "size_geo:%s", size_geo); MagickResetImagePage(ictx->wand, "+0+0"); trans_wand = MagickTransformImage(ictx->wand, (char *)crop_geo, (char *)size_geo); if (trans_wand == NULL || trans_wand == ictx->wand) { r->err_status = NGX_HTTP_INTERNAL_SERVER_ERROR; DestroyString(of_orig); return NGX_ERROR; } DestroyMagickWand(ictx->wand); ictx->wand = trans_wand; } /* create canvas then draw image to the canvas. */ if (sz.cw > 0.0 && sz.ch > 0.0) { canvas_wand = NewMagickWand(); canvas_color = NewPixelWand(); PixelSetRed(canvas_color, sz.cc.r / 255.0); PixelSetGreen(canvas_color, sz.cc.g / 255.0); PixelSetBlue(canvas_color, sz.cc.b / 255.0); PixelSetAlpha(canvas_color, sz.cc.a / 255.0); status = MagickNewImage(canvas_wand, sz.cw, sz.ch, canvas_color); DestroyPixelWand(canvas_color); if (status == MagickFalse) { r->err_status = NGX_HTTP_INTERNAL_SERVER_ERROR; DestroyMagickWand(canvas_wand); DestroyString(of_orig); return NGX_ERROR; } status = MagickTransformImageColorspace(canvas_wand, color_space); if (status == MagickFalse) { r->err_status = NGX_HTTP_INTERNAL_SERVER_ERROR; DestroyMagickWand(canvas_wand); DestroyString(of_orig); return NGX_ERROR; } status = MagickCompositeImage(canvas_wand, ictx->wand, AtopCompositeOp, sz.dx, sz.dy); if (status == MagickFalse) { r->err_status = NGX_HTTP_INTERNAL_SERVER_ERROR; DestroyMagickWand(canvas_wand); DestroyString(of_orig); return NGX_ERROR; } DestroyMagickWand(ictx->wand); ictx->wand = canvas_wand; } /* CMYK to sRGB */ cmyk2rgb_flg = ngx_http_small_light_parse_flag(NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "cmyk2rgb")); if (cmyk2rgb_flg != 0 && color_space == CMYKColorspace) { status = MagickTransformImageColorspace(ictx->wand, sRGBColorspace); if (status == MagickFalse) { r->err_status = NGX_HTTP_INTERNAL_SERVER_ERROR; DestroyString(of_orig); return NGX_ERROR; } } /* effects. */ unsharp = NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "unsharp"); if (ngx_strlen(unsharp) > 0) { ParseGeometry(unsharp, &geo); if (geo.rho > ctx->radius_max || geo.sigma > ctx->sigma_max) { ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "As unsharp geometry is too large, ignored. %s:%d", __FUNCTION__, __LINE__); } else { status = MagickUnsharpMaskImage(ictx->wand, geo.rho, geo.sigma, geo.xi, geo.psi); if (status == MagickFalse) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "unsharp failed %s:%d", __FUNCTION__, __LINE__); } } } sharpen = NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "sharpen"); if (ngx_strlen(sharpen) > 0) { ParseGeometry(sharpen, &geo); if (geo.rho > ctx->radius_max || geo.sigma > ctx->sigma_max) { ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "As sharpen geometry is too large, ignored. %s:%d", __FUNCTION__, __LINE__); } else { status = MagickSharpenImage(ictx->wand, geo.rho, geo.sigma); if (status == MagickFalse) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "sharpen failed %s:%d", __FUNCTION__, __LINE__); } } } blur = NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "blur"); if (ngx_strlen(blur) > 0) { ParseGeometry(blur, &geo); if (geo.rho > ctx->radius_max || geo.sigma > ctx->sigma_max) { ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, "As blur geometry is too large, ignored. %s:%d", __FUNCTION__, __LINE__); } else { status = MagickBlurImage(ictx->wand, geo.rho, geo.sigma); if (status == MagickFalse) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "blur failed %s:%d", __FUNCTION__, __LINE__); } } } /* border. */ if (sz.bw > 0.0 || sz.bh > 0.0) { border_wand = NewDrawingWand(); border_color = NewPixelWand(); PixelSetRed(border_color, sz.bc.r / 255.0); PixelSetGreen(border_color, sz.bc.g / 255.0); PixelSetBlue(border_color, sz.bc.b / 255.0); PixelSetAlpha(border_color, sz.bc.a / 255.0); DrawSetFillColor(border_wand, border_color); DrawSetStrokeColor(border_wand, border_color); DrawSetStrokeWidth(border_wand, 1); if (sz.cw > 0.0 && sz.ch > 0.0) { DrawRectangle(border_wand, 0, 0, sz.cw - 1, sz.bh - 1); DrawRectangle(border_wand, 0, 0, sz.bw - 1, sz.ch - 1); DrawRectangle(border_wand, 0, sz.ch - sz.bh, sz.cw - 1, sz.ch - 1); DrawRectangle(border_wand, sz.cw - sz.bw, 0, sz.cw - 1, sz.ch - 1); } else { DrawRectangle(border_wand, 0, 0, sz.dw - 1, sz.bh - 1); DrawRectangle(border_wand, 0, 0, sz.bw - 1, sz.dh - 1); DrawRectangle(border_wand, 0, sz.dh - sz.bh, sz.dw - 1, sz.dh - 1); DrawRectangle(border_wand, sz.dw - sz.bw, 0, sz.dw - 1, sz.dh - 1); } MagickDrawImage(ictx->wand, border_wand); DestroyPixelWand(border_color); DestroyDrawingWand(border_wand); } /* embed icon */ embedicon = NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "embedicon"); if (ctx->material_dir->len > 0 && ngx_strlen(embedicon) > 0) { if (ngx_strstrn((u_char *)embedicon, "/", 1 - 1)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "invalid parameter 'embedicon':%s %s:%d", embedicon, __FUNCTION__, __LINE__); DestroyString(of_orig); return NGX_ERROR; } embedicon_len = ngx_strlen(embedicon); embedicon_path_len = ctx->material_dir->len + ngx_strlen("/") + embedicon_len; if (embedicon_path_len > sizeof(embedicon_path) - 1) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "embedicon path is too long. maximun value is %z %s:%d", sizeof(embedicon_path) - 1, __FUNCTION__, __LINE__); DestroyString(of_orig); return NGX_ERROR; } p = embedicon_path; p = ngx_cpystrn(p, ctx->material_dir->data, ctx->material_dir->len + 1); p = ngx_cpystrn(p, (u_char *)"/", 1 + 1); p = ngx_cpystrn(p, embedicon, embedicon_len + 1); if ((fd = ngx_open_file(embedicon_path, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0)) == NGX_INVALID_FILE) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "failed to open embeddedicon file:%s %s:%d", embedicon_path, __FUNCTION__, __LINE__); DestroyString(of_orig); return NGX_ERROR; } if (ngx_close_file(fd) == NGX_FILE_ERROR) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "failed to close:%s %s:%d", embedicon_path, __FUNCTION__, __LINE__); DestroyString(of_orig); return NGX_ERROR; } if (ngx_strstrn(embedicon_path, "..", 2 - 1)) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "invalid embeddedicon_path:%s %s:%d", embedicon_path, __FUNCTION__, __LINE__); DestroyString(of_orig); return NGX_ERROR; } icon_wand = NewMagickWand(); if (MagickReadImage(icon_wand, (char *)embedicon_path) == MagickFalse) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "failed to read embed icon image file:%s %s:%d", embedicon_path, __FUNCTION__, __LINE__); DestroyMagickWand(icon_wand); DestroyString(of_orig); return NGX_ERROR; } MagickCompositeImageChannel(ictx->wand, AllChannels, icon_wand, OverCompositeOp, sz.ix, sz.iy); DestroyMagickWand(icon_wand); } /* set params. */ q = ngx_http_small_light_parse_double(NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "q")); if (q > 0.0) { MagickSetImageCompressionQuality(ictx->wand, q); } progressive_flg = ngx_http_small_light_parse_flag(NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "progressive")); if (progressive_flg != 0) { MagickSetInterlaceScheme(ictx->wand, LineInterlace); } of = NGX_HTTP_SMALL_LIGHT_PARAM_GET_LIT(&ctx->hash, "of"); if (ngx_strlen(of) > 0) { type = ngx_http_small_light_type(of); if (type == NGX_HTTP_SMALL_LIGHT_IMAGE_NONE) { ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "of is invalid(%s) %s:%d", of, __FUNCTION__, __LINE__); of = (char *)ngx_http_small_light_image_exts[ictx->type - 1]; } else if (type == NGX_HTTP_SMALL_LIGHT_IMAGE_WEBP) { #if defined(MAGICKCORE_WEBP_DELEGATE) ictx->type = type; #else ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "WebP is not supported %s:%d", __FUNCTION__, __LINE__); of = (char *)ngx_http_small_light_image_exts[ictx->type - 1]; #endif } else { ictx->type = type; } MagickSetFormat(ictx->wand, of); ctx->of = ngx_http_small_light_image_types[ictx->type - 1]; } else { MagickSetFormat(ictx->wand, of_orig); ctx->of = ctx->inf; } DestroyString(of_orig); ctx->content = MagickGetImageBlob(ictx->wand, &sled_image_size); ctx->content_length = sled_image_size; ngx_pfree(r->pool, ctx->content_orig); ictx->complete = 1; return NGX_OK; }