Reputation: 8379
I have a client side code which is used to select portion of the user uploaded image. And I am not using Canvas to crop image as I don't want to sell app performance in low end mobiles. Here is the object that app results
{ scale: 1.4, angle: 270, x: 10, y: 20, w: 400, h: 400, devicePixelRation : 2 }
I am able to rotate, and crop image based on dimensions but would like to know how to scale the image before crop. Thanks. I am using https://github.com/matiasgagliano/guillotine for client side area selection.
Upvotes: 2
Views: 2644
Reputation: 8379
Here is how it can be done! use nodeJS gm module and crop like below
var newW = imageWidth * body.scale, newH = imageHeight * body.scale;
gm(req.files.file.path)
.rotate('white', body.angle)
.resize(newW, newH, '!')
.crop(body.w, body.h, body.x, body.y).write(path, function(err){
});
Upvotes: 3