From 5b01a7b4c2174af96ba3ebcef94d1f56d3a18594 Mon Sep 17 00:00:00 2001 From: Zizon Qiu Date: Mon, 14 Sep 2015 14:46:49 +0800 Subject: [PATCH] Patch:add hint for input image size for some image format like SVG which may contains no size info. without the size hint,convert to other format will fail. this patch try to resolve this issue. --- src/imagemagick.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/imagemagick.cc b/src/imagemagick.cc index ae14c9f..57dbb46 100644 --- a/src/imagemagick.cc +++ b/src/imagemagick.cc @@ -93,7 +93,10 @@ struct convert_im_ctx : im_ctx_base { int flip; std::string srcFormat; - + + unsigned int originWidth; + unsigned int originHeight; + convert_im_ctx() {} }; // Extra context for composite @@ -171,7 +174,12 @@ void DoConvert(uv_work_t* req) { Magick::Blob srcBlob( context->srcData, context->length ); Magick::Image image; - + + // set original image size if provided. + if(context->originWidth !=0 || context->originHeight !=0){ + image.size(Magick::Geometry(context->originWidth,context->originHeight)); + } + if ( !ReadImageMagick(&image, srcBlob, context->srcFormat, context) ) return; @@ -507,6 +515,8 @@ NAN_METHOD(Convert) { context->rotate = obj->Get( NanNew("rotate") )->Int32Value(); context->flip = obj->Get( NanNew("flip") )->Uint32Value(); context->density = obj->Get( NanNew("density") )->Int32Value(); + context->originWidth = obj->Get( NanNew("originWidth") )->Uint32Value(); + context->originHeight = obj->Get( NanNew("originHeight") )->Uint32Value(); Local trimValue = obj->Get( NanNew("trim") ); if ( (context->trim = ! trimValue->IsUndefined() && trimValue->BooleanValue()) ) {