3

I need to use ImageMagic in my java project. I already installed ImageMagic-7.0.3 on Windows 10 (command line works fine)

Then, i added dependency to im4java in maven file. When i try to do some action like:

public static void main(String[] args) {

String imPath="C:\\Program Files\\ImageMagick-7.0.3-Q16";
ConvertCmd cmd = new ConvertCmd();
cmd.setSearchPath(imPath);
IMOperation op = new IMOperation();
op.addImage("biuro.jpg");
op.negate();
op.addImage("biuro_new.jpg");


try {
    cmd.run(op);
} catch (IOException e) {
    e.printStackTrace();
} catch (InterruptedException e) {
    e.printStackTrace();
} catch (IM4JavaException e) {
    e.printStackTrace();
}

System.out.println("works");

}

i get following error

org.im4java.core.CommandException: java.io.FileNotFoundException: convert
    at org.im4java.core.ImageCommand.run(ImageCommand.java:219)
    at Main.main(Main.java:30)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.io.FileNotFoundException: convert
    at org.im4java.process.ProcessStarter.searchForCmd(ProcessStarter.java:661)
    at org.im4java.process.ProcessStarter.startProcess(ProcessStarter.java:399)
    at org.im4java.process.ProcessStarter.run(ProcessStarter.java:312)
    at org.im4java.core.ImageCommand.run(ImageCommand.java:215)
    ... 6 more
Konrad Dziurdź
  • 717
  • 3
  • 8
  • 15
  • 1
    I don't know much about Java, but maybe, as you are using **ImageMagick** version 7, you need to use `magick` as your command rather than `convert`. – Mark Setchell Dec 08 '16 at 19:13
  • As Mark said, you are trying to use Imagemagick 7 with im4java that is likely compatible only with Imagemagick 6. So either make sure that im4java can use IM 7, which uses magick rather than convert. Or uninstall IM 7 and install IM 6. You might get by by installing the legacy components to IM 7. – fmw42 Jan 13 '18 at 00:40

3 Answers3

0

I went trough half of Internet. Read half of google. There was only one small advice saying "have you installed Visual C++ Redistributable and reboot?" That was the solution.

ImageMagick worked in command line, so I did not expected requirement of that type. Moreover I did not find a thing about it in both - im4java and ImageMagick reference.

Hope this will be helpful, and noone ever will waste about 5h of life searching the answer.

Konrad Dziurdź
  • 717
  • 3
  • 8
  • 15
  • Please consider my answer, I really think there is no reason that Visual C++ Redistribuable would be useful. With ImageMagick 7.x, we need to install legacy methods during the setup. Just reinstall and be careful about the options – StevenTB Jan 12 '18 at 21:43
0

Set the user variable under environment variable,Variable name as IM4JAVA_TOOLPATH and Variable Value as C:\Program Files\ImageMagick-7.0.3-Q16. after that kill all the java process and try to run the program.

Other way you can set the global search path like below:

String myPath="C:\\Programs\\ImageMagick;";
ProcessStarter.setGlobalSearchPath(myPath);

This will override your user environmental variable.

Also refer the documentation for more setup related info in detail http://im4java.sourceforge.net/docs/dev-guide.html

Elango Mani
  • 354
  • 4
  • 21
  • I tried this as well, but without Visual C++ Redistributable it cannot be succesfull. I answered to my question above. Anyway, thanks :) – Konrad Dziurdź Jan 10 '17 at 13:11
0

After spending a lot a hours in order to research why I had that issue, the solution is : you need to uninstall then reinstall ImageMagick with "Install legacy utilities (e.g. convert)" during the setup.

StevenTB
  • 405
  • 5
  • 19