Reputation: 1240
I want to change the orientation of an image as from portrait to landscape or vice-versa.
I tried doing it using many of the available npm packages :
* rotate-image
* image-rotate
* jpegorientation
* gm
* rad
But each of these is one way or other not working as I want to do it or each has some or other limitations.
I tried to find a possible solution and search for it as much as I could.
Most of the times,it has been done using gm.
I tried doing the image manipulation using gm :
Code:
var gm = require('gm');
gm('path/filename.jpg')
.autoOrient()
.write('path/destinationfile.jpg', function (err) {
if (err) {
console.log(err);
} else
console.log("Orientation changed successfully!");
})
But I am getting an error as :
Error: Could not execute GraphicsMagick/ImageMagick: gm "identify" "-ping" "-verbose" "path/filename.jpg" this most likely means the gm/convert binaries can't be found.
This error will be resolved only by using external binary libraries.I don't want to involve any kind of dependencies on 3rd party libraries.
Can someone please help me out as of how to do it without pre-installing any of the external binary libraries (brew etc.) or how to use any of the existing package in a better way.
Upvotes: 1
Views: 3357
Reputation: 9766
Mostly likely is the PATH problem (of CentOS). So I would try this:
sudo ln -s /usr/local/bin/gm /usr/bin/gm
sudo ln -s /usr/local/bin/convert /usr/bin/convert
Hope it could help.
Upvotes: 1
Reputation: 19490
You could use the contain method from lwip - Light Weight Image Processor for NodeJS
Here is an example:
// obtain an image object:
require('lwip').open('Example.jpg', function(err, image){
// check err...
// define a batch of manipulations and save to disk as JPEG:
image.batch()
.contain(image.height(), image.width(), 'black')
.writeFile('output.jpg', function(err){
// check err...
console.log(err || 'Done');
});
});
This swaps the orientation and fills the gaps in black.
I just tried it, and i only needed to install the lwip module into my application.
npm install lwip --save
Upvotes: 3