Question

I have set up on client Jcrop and on Server a imagemagick (express.js).

Image is uploaded to server first, and then shown to the client. Client makes crop, and the following information is sent to server:

function showCoords(c)
{
  // variables can be accessed here as
  // c.x, c.y, c.x2, c.y2, c.w, c.h
};

I have the image stored on server ready to be cropped. Question is, if using imagemagick... how do I use those variables? Image magick has resize and crop (it has other options as well) that seem to be relevant... but it seems that I have more variables then the IM accepts.

What is going on?

Was it helpful?

Solution

You can ignore point2 (c.x2,x.y2). Jcrop is just being helpful by giving you a rectangles size (c.w,c.h), starting point (c.x,c.y), and ending point (c.x2,c.y2).

points

ImageMagick has it's own Image Geometry format, so you just need the size & offset (starting point).

function showCoords(c)
{
   var IMGeometry = String.concat(c.w,"x",c.y,"+",c.x,"+",c.y);
   //=> "175x125+50+50"

   // Assuming you are using node-imagemagick
   im.convert(["source.jpg","-crop",IMGeometry,"out.jpg"],function(err, stdout){
     // Callback
   });
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top