Last active
August 29, 2015 14:14
-
-
Save pgherveou/2440e4209098700961ac to your computer and use it in GitHub Desktop.
transform image to a square rounded thumbnail
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 fs = require('fs') | |
var spawn = require('child_process').spawn | |
var convertToSquare = spawn('convert', ['-quality', '1', '-', '-resize', '150x150^^', '-gravity', 'Center', '-extent', '150x150', 'PNG32:-']) | |
var convertToCircle = spawn('convert', ['-size', '150x150', 'xc:none', '-fill', '-', '-draw', 'circle 75,75 75,1', 'PNG32:-']) | |
var readFile = fs.createReadStream('image.png') | |
var writeFile = fs.createWriteStream('image-150x150-circle.png') | |
readFile.pipe(convertToSquare.stdin) | |
convertToSquare.stdout.pipe(convertToCircle.stdin) | |
convertToCircle.stdout.pipe(writeFile) | |
convertToSquare.stderr.pipe(process.stderr); | |
convertToCircle.stderr.pipe(process.stderr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment