Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How do I configure a JPEG delegate for graphicsmagick?

How do I configure a JPEG delegate for graphicsmagick?

Problem

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:


     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

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
Problem courtesy of: Plato

Solution

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) };
});
Solution courtesy of: Plato

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How do I configure a JPEG delegate for graphicsmagick?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×