2

My requirement is to convert multiple jpeg files to a multi-page Tiff file. Initially, I've gone through this post and I was able to create tiff files in java using jai_imageio libraries but unfortunately these libraries are not open source. Later, I've heard about ImageMagick which could exactly give me what I want. I installed ImageMagick in my machine and I wrote a small utility program which takes multiple jpegs as input and gives a TIFF file as output.

The code:

try {
    Process p = Runtime
        .getRuntime()
        .exec("C:/Program Files/ImageMagick-6.8.8-Q16/convert E:/1.jpg E:/2.jpg E:/3.jpg -compress JPEG " 
    +"E:/mul.tiff");
    p.waitFor();

    } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
}

The utility works very fine but the problem with the above program is, I cannot debug and the above code wouldn't throw any error even if I specify wrong path for input files.

I know about Jmagick which provides a Java Interface for ImageMagick. It'd be helpful for me if anyone provides me a Jmagick sample program in java which can create multi-page tiff by multiple jpegs as input.

Thanks.

Community
  • 1
  • 1
chaitanya89
  • 827
  • 3
  • 20
  • 26

1 Answers1

0

After a lot of googling, I found im4java which helped me to convert multiple jpegs to a single tiff. It is a java wrapper for ImageMagick. And for the set-up and examples visit this. Download the required jars here and put it in your classpath.

Here's the sample code I'm using.

     // create the operation, add images and operators/options
        ConvertCmd cmd = new ConvertCmd();
        IMOperation op = new IMOperation();
        op.addImage("E:/jpeg/001.jpg");
        op.addImage("E:/jpeg/003.jpg");
        op.addImage("E:/jpeg/006.jpg");

        op.compress("JPEG");
        op.format("TIFF");// set the format.
        op.addImage("E:/im4j-compressed.tiff");

        // execute the operation
        cmd.run(op);
chaitanya89
  • 827
  • 3
  • 20
  • 26