From 2b34173decaf1bc38dbd6d2fc66a98079770a221 Mon Sep 17 00:00:00 2001 From: Ryan Wersal Date: Mon, 5 May 2014 22:47:33 -0500 Subject: [PATCH] Add ability to add base64 URI images --- lib/image.coffee | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/image.coffee b/lib/image.coffee index b1d420e..e46e8bb 100644 --- a/lib/image.coffee +++ b/lib/image.coffee @@ -13,8 +13,13 @@ class PDFImage if Buffer.isBuffer(src) data = src else - data = fs.readFileSync src - return unless data + if src[0..4] is 'data:' and src.indexOf(';base64,') > -1 + base64String = src.split(';base64,')[1] + data = new Buffer(base64String, 'base64') + + else + data = fs.readFileSync src + return unless data if data[0] is 0xff and data[1] is 0xd8 return new JPEG(data, label)