From 6143792c201b270a1172acf7a3734baa60ae53b7 Mon Sep 17 00:00:00 2001 From: Joschi Kuphal Date: Sat, 14 May 2016 10:15:57 +0200 Subject: [PATCH 1/2] Added page.clipRect for rasterizing via PhantomJS --- lib/converter.js | 6 ++++++ 1 file changed, 6 insertions(+) mode change 100644 => 100755 lib/converter.js diff --git a/lib/converter.js b/lib/converter.js old mode 100644 new mode 100755 index ff55f58..2d52b7d --- a/lib/converter.js +++ b/lib/converter.js @@ -43,6 +43,12 @@ function convert(resize) { width: dimensions.width, height: dimensions.height }; + page.clipRect = { + top: 0, + left: 0, + width: dimensions.width, + height: dimensions.height + }; } catch (e) { console.error("Unable to calculate or set dimensions."); console.error(e); From 09a03c6c0d32a0046593f13fe87dfdf2b7e4a47f Mon Sep 17 00:00:00 2001 From: Joschi Kuphal Date: Sat, 14 May 2016 11:19:30 +0200 Subject: [PATCH 2/2] Force PhantomJS to reload the SVG after setting dimensions --- lib/converter.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/converter.js b/lib/converter.js index 2d52b7d..6201af8 100755 --- a/lib/converter.js +++ b/lib/converter.js @@ -34,7 +34,7 @@ function convert(resize) { var dimensions = getSVGDimensions(page); if (!dimensions) { console.error("Width or height could not be determined from either the source file or the supplied " + - "dimensions"); + "dimensions"); phantom.exit(); return; } @@ -49,16 +49,17 @@ function convert(resize) { width: dimensions.width, height: dimensions.height }; + page.open(PREFIX + sourceBase64, function (status) { + var result = "data:image/png;base64," + page.renderBase64("PNG"); + system.stdout.write(result); + phantom.exit(); + }) } catch (e) { console.error("Unable to calculate or set dimensions."); console.error(e); phantom.exit(); return; } - - var result = "data:image/png;base64," + page.renderBase64("PNG"); - system.stdout.write(result); - phantom.exit(); }); }