ImageMagick / IM4J FileNotFoundException

I am trying to use IM4J (the Java wrapper for ImageMagick) to create JPEG thumbnails, and this is my first experience (ever) from both libraries. Please note that this is a strict requirement that my technical guide passed to me (therefore, please do not offer to use anything other than IM4J / ImageMagick) - my hands are connected with the choice of technology here!

I get a command FileNotFoundExceptionin a command and convertthat tells me that I do not have one of these libraries (or both) correctly configured.

On my computer, here is my directory structure:

C:/
    myApp/
        images/             --> where all of my JPEGs are
        thumbnails/         --> where I want ImageMagick to send the converted thumbnails to
        imageMagickHome/    --> Where I downloaded the DLL to
            ImageMagick-6.7.6-1-Q16-windows-dll.exe
    ...

In my Java project, I make sure that the IM4J JAR ( im4java-1.2.0.jar) is in the classpath at runtime. Although I must use IM4J version 1.2.0, I have the right to use any version of ImageMagick that I want. I just chose this version because it seemed like the most modern / stable version for my Windows 7 (32-bit) machine. If I have to use a different version, send me a link to it from the ImageMagick download page in your answer!

As for ImageMagick, I just downloaded the EXE from here and put it in the above folder - I did not do any installation, wizard, MSI, configuration of environment variables, etc.

Then in my Java code:

// In my driver...
File currentFile = new File("C:/myApp/images/test.jpg"); --> exists and is sitting at this location
File thumbFile = new File("C:/myApp/thumbnails/test-thumb.jpg"); --> doesnt exist yet! (destination file)
Thumbnailer myThumbnailer = new Thumbnailer();
myThumbnailer.generateThumbnail(currentFile, thumbFile);

// Then the Thumbnailer:
public class Thumbnailer
{
    // ... omitted for brevity

    public void generateThumbnail(File originalFile, File thumbnailFile)
    {
        // Reads appConfig.xml from classpath, validates it against a schema,
        // and reads the contents of an element called <imPath> into this
        // method return value. See below
        String imPath = getIMPathFromAppConfigFile();

        org.im4java.core.IMOperation op = new Operation();
        op.colorspace(this.colorSpace);
        op.addImage(originalFile.getAbsolutePath());
        op.flatten();
        op.addImage(thumbnailFile.getAbsolutePath());

        ConvertCmd cmd = new ConvertCmd();

        cmd.setSearchPath(imPath);

        // This next line is what throws the FileNotFoundException
        cmd.run(op);
    }
}

The section of my appConfig.xml file that contains imPath:

<imPath>C:/myApp/imageMagickHome</imPath>

: appConfig.xml , . , - . , ; . , , Windows , * nix, . , Windows Linux-, ( , !).

IM4J , Windows , Windows, , IM4JAVA_TOOLPATH env var . , C:\myApp\imageMagickHome. . , . , env var , appConfig.xml - , Linux.

, , , , ( ) :

  • " " ImageMagick EXE /MSI; ImageMagick ( IM4J)
  • , IM4J .
  • Windows/* nix "/" "\" appConfig.xml, .

, FileNotFoundException "convert":

java.io.FileNotFoundException: convert

, /, - IM4J ( , ImageMagick, EXE). , IM4J, . "script generator", , cmd.run(op) convert, , , , (, , CmdScriptGenerator Thumbnailer. , , .

, , , .

.

+3
2

"ImageMagick-6.7.6-1-Q16-windows-dll.exe", imagemagick. , ( "convert.exe", "mogrify.exe" ..)

+1

, IM4JAVA_TOOLPATH.

enter image description here

0

All Articles