Created
October 20, 2016 17:15
-
-
Save bbrewer97202/ede3902f2bced2f1125cc560e6f4b4b1 to your computer and use it in GitHub Desktop.
Graphicsmagick gm convert svg string buffer to sized jpg with 300 DPI setting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gm = require('gm'); | |
var source = '<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 2550 3300" enable-background="new 0 0 2550 3300" xml:space="preserve"><g><path fill="#53381A" stroke="#1C1308" d="M807.6,1092.5L527.3,1067c-636.9-25.5-509.5,0-458.6,509.5c51,203.8,0,331.2,254.8,331.2 L807.6,1092.5z"/><path fill="#8A5B28" stroke="#1C1308" d="M909.5,1143.5H629.2c-636.9-25.5-509.5,0-458.6,509.5c51,203.8,25.5,305.7,305.7,229.3 L909.5,1143.5z"/><path fill="#454F2E" stroke="#1C1308" d="M807.6,990.6c127.4-254.8,76.4-305.7,458.6-254.8c509.5,127.4,509.5,152.9,891.6,152.9 c254.8,25.5,509.5,101.9,254.8,407.6l-280.2,509.5H450.9L807.6,990.6z"/><path fill="#76894C" stroke="#1C1308" d="M323.5,1703.9v178.3l1146.4,458.6v-178.3L323.5,1703.9z M807.6,990.6 c127.4-254.8,76.4-305.7,382.1-203.8c509.5,152.9,254.8,152.9,789.7,152.9c254.8,25.5,458.6,101.9,254.8,407.6L1954,1856.8 L527.3,1627.5L807.6,990.6z"/><path fill="#8E996C" stroke="#1C1308" d="M323.5,1703.9c-76.4-254.8,51-229.3,254.8-254.8c254.8-25.5,942.6,178.3,509.5,178.3 c-305.7,25.5-305.7,0-305.7,254.8L323.5,1703.9z M782.1,1882.3c-51-356.7,331.2-203.8,509.5-254.8l178.3,76.4v458.6L782.1,1882.3z" /><path fill="#53381A" stroke="#1C1308" d="M1444.4,1933.2c25.5,509.5,0,484,458.6,484c509.5,0,433.1,0,484-433.1 c0-433.1-25.5-407.6-458.6-458.6C1419,1500.1,1444.4,1525.6,1444.4,1933.2z"/><path fill="#8A5B28" stroke="#1C1308" d="M1520.9,1984.2c25.5,509.5,0,484,458.6,484c509.5,0,433.1,0,484-433.1 c0-433.1-25.5-407.6-458.6-458.6C1495.4,1551.1,1520.9,1576.6,1520.9,1984.2z"/></g></svg>'; | |
var buf = new Buffer(source); | |
gm(buf, 'svg.svg') | |
.resize(2550, 3300) | |
.density(300, 300) | |
.noProfile() | |
.write('./out.jpg', function (err) { | |
if (err) { | |
console.log(err); | |
} else { | |
console.log('done'); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment