How to use graphicsmagick crop circle picture?
(use png transparent background outer circle)
I use graphicsmagick in node.js , or have any other way make this in node.js?
I use another module to solve this problem:
this code is for square image (this.height = this.width)
var fs = require('fs'),
PNG = require('pngjs').PNG;
fs.createReadStream(__dirname + "/input.png")
.pipe(new PNG({
filterType: 4
}))
.on('parsed', function() {
for (var y = 0; y < this.height; y++) {
for (var x = 0; x < this.width; x++) {
var idx = (this.width * y + x) << 2;
var radius = this.height / 2;
if(y >= Math.sqrt(Math.pow(radius, 2) - Math.pow(x - radius, 2)) + radius || y <= -(Math.sqrt(Math.pow(radius, 2) - Math.pow(x - radius, 2))) + radius) {
this.data[idx + 3] = 0;
}
}
}
this.pack().pipe(fs.createWriteStream(__dirname + "/output.png"));
});
I was able to do it with the following plugin: https://www.npmjs.com/package/circle-image
After you install it:
var images = require('circle-image');
var imageSizes = [125, 100, 30];
//uniqueId param is used to identify a user
//so user the primary key or something guaranteed to be unique
images.execute('imagepath', uniqueId, imageSizes).then(function (paths) {
//array of circularized image paths
console.log(paths[0]); //circle_user_{uniqueId}_150.png
})