3

I'm coding an application using Java and I need to resize some images, so I've been learning about ImageMagick. The command I need to use for my purposes is:

convert -resize 500x500\> -quality 85% -strip -interlace Plane -define jpeg:dot-method=float source.jpg destination.jpg

Using Java, I think I could use:

Runtime.getRuntime().exec(command);

Isn't it?

But, if I rather user an API like JMagick... how could I proceed to compose what I want to do?

Thank you very much! Regards.

Ommadawn
  • 2,450
  • 3
  • 24
  • 48
  • I don't know about jmagic but there is an interface for imagemagic command line i.e. im4j. follow the link for examples http://im4java.sourceforge.net/docs/dev-guide.html – Prabhat Jun 09 '16 at 10:30
  • @zombie is not the same kind of interface JMagick and im4j? By the way... im4j website says last update was in 2012 :O – Ommadawn Jun 09 '16 at 16:24

1 Answers1

2

After investigate and read a lot from IM4J API, I did this:

IMOperation op = new IMOperation();

op.resize(500, 500, '>');
op.quality(85.0); // jpeg quality (%)
op.strip(); // remove EXIF comments
op.interlace("Plane"); // progressive-mode
op.define("jpeg:dot-method=float"); // float processing (more quality, but slower)
op.addImage("my_original_pic.jpg");
op.addImage("my_resized_pic.jpg");

ConvertCmd convert = new ConvertCmd();
convert.run(op);

And that's all! :)

If you want to use mogrify command, you can re-use the IMOperation object and just have to do this:

MogrifyCmd mogrify = new MogrifyCmd();
mogrify.run(op);

But remember that mogrify command doesn't have a second pic input parameter.

Ommadawn
  • 2,450
  • 3
  • 24
  • 48