I am using gm for node.js on linux server with express.js . It works fine with images less than 2MB filesize. But the moment it exceeds that the code stops working. Here's the code
gm('public/'+article.page.image)
.resize(width,height)
.quality(80)
.write('public/article_image/'+ folder + '/' + "something.jpg", function(err){
if (err){
console.log('error occurred')
console.log(err)
}
else{
console.log('resized image 16')
somefunction(16, true);
}
})
The error I am facing goes
Error: Command failed:
at ChildProcess.onExit (/root/patarboi/node_modules/gm/lib/command.js:301:17)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at maybeClose (internal/child_process.js:920:16)
at Socket.<anonymous> (internal/child_process.js:351:11)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at Pipe._handle.close [as _onclose] (net.js:497:12) code: null, signal: 'SIGSEGV'
How to solve this?
The problem was causing because of segmentation error of imagemagick. I was using an old version of imagemagick. Instead of installing like this.
sudo apt-get install ImageMagick
find the latest version of imagemagick from here. Then install it like below. At present the latest version is ImageMagick-7.0.7-22.tar.gz. At first build the dependency. Then get it from the url.
$sudo apt-get install build-essential checkinstall && apt-get build-dep imagemagick -y
$sudo wget http://www.imagemagick.org/download/ImageMagick-7.0.7-22.tar.gz
Now unzip
$sudo tar xzvf 7.0.7-22.tar.gz
Move to the directory
cd ImageMagick-7.0.7-22
Check the configuration ./configure Now build the code
make clean
make
checkinstall
ldconfig /usr/local/lib
To check if the installation is done
convert -version