I want to crop an image to a specified pixel region. I'd like to use the gm
module from https://github.com/aheckmann/gm.
I am running Linux Mint 13 and node.js v0.9.4pre.
I am running into an error that sounds like graphicsmagick doesn't know about jpegs:
Error: Command failed: gm convert: No decode delegate for this image format (./assets/images/temp/2aadd4379e1cf2b59429994270db2a8a.jpg)
Sure enough, gm convert -list formats
shows no jpeg delegate:
<snip>
IPTC P rw- IPTC Newsphoto
IPTCTEXT P rw- IPTC Newsphoto text format
IPTCWTEXT P rw- IPTC Newsphoto text format
K25 S r-- Kodak Photo RAW
<snip>
graphicsmagick has a ftp folder containing source code for delegates (with a readme.) So I downloaded, untarred, and installed jpegsrc.v6b.tar.gz
as suggested in both the install document that came with my source files.
I'm pretty sure the jpeg library installed cjpeg
and djpeg
and perhaps other stuff. However there is no make uninstall
or manifest that I found. I haven't tried installing any other versions of the jpeg library over this one. I uninstalled and rebuilt graphicsmagick after installing the jpeg library.
Still, there is no JPEG delegate listed in gm convert -list formats
.
I am migrating from Imagemagick which never had any problems resizing jpegs, even without my installing this library.
What must I do to get graphicsmagic to handle jpegs?
Here's how I am invoking gm:
var gmagic = require('gm');
gmagic(cfg.tmpPath)
.crop(h,w,x0,y0)
.write(cfg.croppedPath, function(err){
if(err){ done(err) }
else { done(null, cfg.croppedPath) };
});
Here are the commands I used to install the jpeg library and graphicsmagick:
$ cd ~/source
$ wget http://www.ijg.org/files/jpegsrc.v6b.tar.gz
$ tar -xzvf jpegsrc.v6b.tar.gz
$ cd jpeg-6b
$ ./configure
$ make
$ sudo make install
$ cd ~/source
$ wget ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/1.3/GraphicsMagick-1.3.18.tar.xz
$ tar -xJvf GraphicsMagick-1.3.18.tar.xz
$ cd GraphicsMagick-1.3.18
$ ./configure
$ make
$ sudo make install
$ npm install gm
I found a successful workaround by telling the gm library to use imagemagick binaries instead of default graphicsmagic binaries:
var gmagic = require('gm');
var imagic = gmagic.subClass({imageMagick: true});
...
imagic(cfg.tmpPath)
.crop(h,w,x0,y0)
.write(cfg.croppedPath, function(err, stdout, stderr, command){
if(err){ next(err) }
else { next(null, raft) };
});
Given that you are using Linux Mint, the best solution for GraphicsMagick to find libjpeg is to install the libjpeg development package (libjpeg-dev), re-run the GraphicsMagick configure script, rebuild, and install. Be sure to add -dev packages for libraries supporting other formats you are interested in.
If you want to use the libjpeg installed from source code, then you will need to add the options LDFLAGS=-L/usr/local/lib CPPFLAGS=-I/usr/local/include to the GraphicsMagick configure script invocation. Be aware that Linux Mint may come with a different libjpeg than jpeg 6b (e.g. jpeg 8 or libjpeg turbo) and it is best not to have duplicate libraries on the system.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With