Earlier this year I became obsessed with different types of media (images, audio, video) and how to convert and merge one format to/with another. Half of that obsessions is due to fascination in how it’s done, the other half is love of performance. A few of my favorites include:
- Resize an Animated GIF
- Combine Audio and Video with ffmpeg
- Create an Image Preview from a Video
- Convert Video to GIF or GIF to Video
- Get the First Frame of an Animated GIF with ImageMagick
Image format conversion and optimization tantalizes me the most because it’s usually a case of very little effort making a big difference, a la using image compression utilities like ImageOptim to turn a bloated image to an image half the size with little reduction in quality. The latest tool I’ve found is svg2png, a Node.js utility for turning a SVG image into a static PNG!
require('svg2png')('dino.svg', 'dino.png', function(err) { console.log('An error occurred during conversion: ', err); });
You can even perform scaling via another argument:
require('svg2png')('dino.svg', 'dino.png', 2.5, function(err) { console.log('An error occurred during conversion and upscaling: ', err); });
Here’s a side by side comparison of the SVG and PNG:
A simple API, performs one function well — what more can you ask for? I look forward to using this module to decrease the image sizes on each of the sites I work on!
Source: David Walsh