You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP โ†’
Socket
Book a DemoInstallSign in
Socket

svg-to-png

Package Overview
Dependencies
Maintainers
6
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svg-to-png - npm Package Compare versions

Comparing version

to
4.0.0

test/viewbox/Internet-100pct-width-100pct-height-no-viewbox.svg

8

lib/processor.js

@@ -35,2 +35,8 @@ /*global require:true*/

var height = svgelem.getAttribute( "height" );
var viewbox = svgelem.getAttribute( 'viewBox' );
if (viewbox && width === '100%' && height === '100%') {
viewbox = viewbox.split(" ");
width = viewbox[2] + 'px';
height = viewbox[3] + 'px';
}
if( width ){

@@ -71,3 +77,3 @@ data.width = width.replace(pxre, "$1px");

} else {
reject( status + ": " + "Phantom had an error opening - " + filename + " - " + "Does it exist? " + fs.exists(filename));
reject( status + ": " + "Phantom had an error opening - " + filename + " (" + gFile.uri + ") - " + "Does it exist? " + fs.exists(filename));
}

@@ -74,0 +80,0 @@ }); //page.open

40

lib/svg-to-png.js

@@ -26,3 +26,2 @@ /*

var RSVP = require( './rsvp' );
var phantomJsPath = require('phantomjs-prebuilt').path;

@@ -34,3 +33,3 @@ var phantomfile = path.join( __dirname, 'phantomscript.js' );

var convertNoCompress = function( files, outputDir, opts ){
return new RSVP.Promise(function(resolve, reject){
return new Promise(function(resolve, reject){
execFile( phantomJsPath,

@@ -53,3 +52,5 @@ [

} else {
console.log( stdout );
if( (stdout || "").trim() ) {
console.log( stdout );
}
resolve( outputDir );

@@ -68,3 +69,3 @@ }

var tempDir = path.join( os.tmpdir(), "svg-to-png" + (new Date()).getTime() );
return new RSVP.Promise(function(resolve, reject){
return new Promise(function(resolve, reject){
execFile( phantomJsPath,

@@ -87,18 +88,19 @@ [

} else {
console.log( stdout );
if( (stdout || "").trim() ) {
console.log( stdout );
}
opts = opts || {};
opts.optimizationLevel = opts.optimizationLevel || 3;
var imagemin = new Imagemin()
.src( tempDir + '/*.{gif,jpg,png,svg}' )
.dest(outputDir)
.use(Imagemin.optipng(opts));
var imagemin = Imagemin(
[tempDir + '/*.{gif,jpg,png,svg}'],
outputDir,
opts);
imagemin.run(function (err, files) {
if (err) {
imagemin.
then(function (files) {
resolve(files);
}).catch(function(err){
reject(err);
}
resolve(files);
});
});
}

@@ -120,6 +122,6 @@ });

files = [ input ];
} else if( Array.isArray( input ) ){
} else if( Array.isArray( input ) && input.filter(function(file) { return fs.existsSync( file ) && fs.lstatSync( file ).isFile(); }).length ){
files = input;
} else {
throw new Error( "Input must be Array of files or String that is a directory" );
throw new Error( "Input must be Array of existing files or String that is a directory" );
}

@@ -151,4 +153,4 @@

// take it to phantomjs to do the rest
console.log( "svg-to-png now spawning phantomjs..." );
console.log('(using path: ' + phantomJsPath + ')');
opts.debug && console.log( "svg-to-png now spawning phantomjs..." );
opts.debug && console.log('(using path: ' + phantomJsPath + ')');

@@ -155,0 +157,0 @@ if( opts.compress ){

{
"name": "svg-to-png",
"description": "Converts SVGs to PNGs",
"version": "3.1.2",
"version": "4.0.0",
"homepage": "https://github.com/filamentgroup/svg-to-png",
"author": {
"name": "Jeffrey Lembeck/Filament Group",
"name": "Jeffrey Lembeck, Zach Leatherman & Filament Group",
"email": "hello@filamentgroup.com",

@@ -21,3 +21,3 @@ "url": "http://filamentgroup.com"

"engines": {
"node": ">= 0.8.0"
"node": ">=4"
},

@@ -28,2 +28,3 @@ "scripts": {

"dependencies": {
"imagemin": "^6.0.0",
"phantomjs-prebuilt": "^2.1.7"

@@ -33,12 +34,10 @@ },

"grunt": "^1.0.1",
"grunt-contrib-jshint": "^1.0.0",
"grunt-contrib-nodeunit": "^1.0.0",
"grunt-contrib-jshint": "^2.0.0",
"grunt-contrib-nodeunit": "^2.0.0",
"grunt-contrib-qunit": "^1.2.0",
"grunt-contrib-watch": "^1.0.0",
"image-size": "^0.6.3",
"phantom-unit": "^1.0.1"
},
"optionalDependencies": {
"imagemin": "3.1.0"
},
"keywords": []
}

@@ -46,7 +46,8 @@ # svg-to-png [![Build Status](https://secure.travis-ci.org/filamentgroup/svg-to-png.png?branch=master)](http://travis-ci.org/filamentgroup/svg-to-png)

* defaultWidth: normally 400px
* defaultHeight: normally 300px
* compress: Default `false`, if `true`, will compress your png file
* `defaultWidth`: normally 400px
* `defaultHeight`: normally 300px
* `compress`: Default `false`, if `true`, will compress your png file
using optipng
* optimizationLevel: Default `3`, if compress is set to `true`, this will set the optimationLevel for optipng
* `optimizationLevel`: Default `3`, if compress is set to `true`, this will set the optimationLevel for optipng
* `debug`: enables console log output

@@ -59,2 +60,10 @@ ## Examples

## Roadmap
This repository is now using [lodash style issue management](https://twitter.com/samselikoff/status/991395669016436736) for enhancements. This means enhancement issues will now be closed instead of leaving them open.
The enhancement backlog can be found here: https://github.com/filamentgroup/svg-to-png/issues?utf8=%E2%9C%93&q=label%3Aneeds-votes+sort%3Areactions-%2B1-desc+
Donโ€™t forget to upvote the top comment of each issue with ๐Ÿ‘!
## Release History

@@ -61,0 +70,0 @@ * v2.0.0 - Breaking change, pngfolder no longer works nor is there at

@@ -28,5 +28,5 @@ /*

var fs = require( 'fs' );
var sizeOf = require( 'image-size' );
var svg_to_png = require(path.join( "..", "lib", "svg-to-png.js") );
exports.convert = {

@@ -81,2 +81,66 @@ setUp: function(done) {

};
exports.checkOutputSize = {
setUp: function(done) {
// setup here
done();
},
tearDown: function( done ){
if( fs.existsSync( path.join( __dirname, "output", "Internet-44px-width-44px-height.png" )) ){
fs.unlinkSync( path.join( __dirname, "output", "Internet-44px-width-44px-height.png" ) );
}
if( fs.existsSync( path.join( __dirname, "output", "Internet-no-width-no-height.png" )) ){
fs.unlinkSync( path.join( __dirname, "output", "Internet-no-width-no-height.png" ) );
}
if( fs.existsSync( path.join( __dirname, "output", "Internet-100pct-width-100pct-height.png" )) ){
fs.unlinkSync( path.join( __dirname, "output", "Internet-100pct-width-100pct-height.png" ) );
}
if( fs.existsSync( path.join( __dirname, "output", "Internet-100pct-width-100pct-height-no-viewbox.png" )) ){
fs.unlinkSync( path.join( __dirname, "output", "Internet-100pct-width-100pct-height-no-viewbox.png" ) );
}
done();
},
'px width/height, and viewbox': function(test) {
test.expect(1);
// tests here
svg_to_png.convert( path.join(__dirname, "viewbox", "Internet-44px-width-44px-height.svg" ), path.join( __dirname, "output" ) )
.then( function(){
sizeOf(path.join( __dirname, "output", "Internet-44px-width-44px-height.png" ), function (err, dimensions) {
test.ok(dimensions.width === 44 && dimensions.height === 44);
test.done();
});
});
},
'no width/height, and viewbox': function(test) {
// tests here
svg_to_png.convert( path.join(__dirname, "viewbox", "Internet-no-width-no-height.svg" ), path.join( __dirname, "output" ) )
.then( function(){
sizeOf(path.join( __dirname, "output", "Internet-no-width-no-height.png" ), function (err, dimensions) {
test.ok(dimensions.width === 400 && dimensions.height === 300);
test.done();
});
});
},
'100% width/height, and viewbox': function(test) {
// tests here
svg_to_png.convert( path.join(__dirname, "viewbox", "Internet-100pct-width-100pct-height.svg" ), path.join( __dirname, "output" ) )
.then( function(){
sizeOf(path.join( __dirname, "output", "Internet-100pct-width-100pct-height.png" ), function (err, dimensions) {
test.ok(dimensions.width === 44 && dimensions.height === 44);
test.done();
});
});
},
'% width/height, and no viewbox': function(test) {
// tests here
svg_to_png.convert( path.join(__dirname, "viewbox", "Internet-100pct-width-100pct-height-no-viewbox.svg" ), path.join( __dirname, "output" ) )
.then( function(){
sizeOf(path.join( __dirname, "output", "Internet-100pct-width-100pct-height-no-viewbox.png" ), function (err, dimensions) {
test.ok(dimensions.width === 100 && dimensions.height === 100);
test.done();
});
});
}
};
exports.convertWithDir = {

@@ -107,8 +171,6 @@ setUp: function(done) {

// tests here
svg_to_png.convert( [path.resolve( path.join(__dirname, "files", "foo.svg") )], path.resolve( path.join( __dirname,"output") ) )
.then( function(){
}, function(err){
test.ok( err );
test.done();
test.throws(function() {
svg_to_png.convert( [path.resolve( path.join(__dirname, "files", "foo.svg") )], path.resolve( path.join( __dirname,"output") ) );
});
test.done();
},

@@ -115,0 +177,0 @@ 'two args - first is file': function(test) {

Sorry, the diff of this file is not supported yet