File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,23 @@ function convertSVGBufferToPNG(buf, dest) {
3838 } ) ;
3939}
4040
41+ // Converts a inline data: to png file
42+ function convertInlinePNG ( source , dest ) {
43+ if ( ! / ^ d a t a \: i m a g e \/ p n g / . test ( source ) ) return Promise . reject ( new Error ( 'Source is not a PNG data-uri' ) ) ;
44+
45+ var base64data = source . split ( 'data:image/png;base64,' ) [ 1 ] ;
46+ var buf = new Buffer ( base64data , 'base64' ) ;
47+
48+ return fs . writeFile ( dest , buf )
49+ . then ( function ( ) {
50+ if ( fs . existsSync ( dest ) ) return ;
51+
52+ throw new Error ( 'Error converting ' + source + ' into ' + dest ) ;
53+ } ) ;
54+ }
55+
4156module . exports = {
4257 convertSVGToPNG : convertSVGToPNG ,
43- convertSVGBufferToPNG : convertSVGBufferToPNG
58+ convertSVGBufferToPNG : convertSVGBufferToPNG ,
59+ convertInlinePNG : convertInlinePNG
4460} ;
You can’t perform that action at this time.
0 commit comments