ImageMagick’s official documentation suggests two libraries to work with Java.
JMagick
Jmagick looked promising. It provides an object-oriented Java interface to ImageMagick. 1
But the linked website is down, and the Maven package has almost no usage 2, and it is challenging to find any documentation or example. When you find it, it depends on many operational system specific files scattered in different directories. 3 If you could make it work on your development machine 4, you would have difficulty making it work on the production machine.
im4java
To use im4java, you only need ImageMagick installed on the host machine. im4java generates the command line for the ImageMagick commands and passes the generated line to the selected IM-command (using the java.lang.ProcessBuilder.start()
method). 5
To use im4java
Now a command line like this:
convert myimage.jpg -resize 800x600 myimage_small.jpg
Could be written in Java like this: 6
// create command
ConvertCmd cmd = new ConvertCmd();
// create the operation, add images and operators/options
IMOperation op = new IMOperation();
op.addImage("myimage.jpg");
op.resize(800,600);
op.addImage("myimage_small.jpg");
// execute the operation
cmd.run(op);
It could be helpful when reusing code and working with conditionals. It also makes it easy to understand complex command line tasks.