Search code examples
javaim4java

Why this im4java gives exception in java


I want to provide my clients the ability to resize and watermark images in an application developed with Java. After searching the Internet, I have provided the im4java library with my application by simply adding it. I saw different articles and got this code:

try 
{
    IMOperation op = new IMOperation();
    op.addImage("d:\\abc.jpg");
    op.addImage("d:\\def.jpg");
    new ConvertCmd().run(op);
} 
catch (IOException | InterruptedException | IM4JavaException e) 
{
    System.out.println(e.toString());
}

it gives exception as

org.im4java.core.CommandException: org.im4java.core.CommandException: Invalid Parameter - d:\def.jpg

why is that so?

1) Do I have to install any external library on my PC other than just adding im4java library to my application?

2) If I do have to install some kind of other library on my PC then will my clients have to install it too on their machine as well or is their any solution?

In this question here How do you resize an image using im4java?, an answer says I need an interface for this, What does this means? And if I somehow install this interface on my machine, what my clients will have to do? Can't this be embedded like H2 database so my clients don't have to install anything else other than my software?


Solution

  • im4java is simply a wrapper for ImageMagick, an old school tool chain that can be started from command line then process images. If you don't install ImageMagick, things won't work at all!

    The org.im4java.core.CommandException you've encountered may perhaps be caused by convert.exe of the same name, a built-in disk utility on Windows which can convert FAT volumes into NTFS ones

    A feasible way to solve your problem is to use a portable version of ImageMagick. For Windows just download the zip file (ImageMagick-6.8.9-8-Q16-x86-windows.zip, the version may vary) and extract it. For other platforms it is better to build a portable version from source.

    Once you make ImageMagick utilities portable, you can put them relative to your program, then add an extra ProcessStarter.setGlobalSearchPath(...) line to specify the search path at the beginning of your code. You can then ship them (portable ImageMagick, im4java, your program...) altogether to your clients.