Add ability to add base64 URI images

This commit is contained in:
Ryan Wersal 2014-05-05 22:47:33 -05:00
parent 16e8b0316f
commit 2b34173dec

View File

@ -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)