[Yanel-dev] Use of ImageMagick with Yanel/Yarep

Mehmet Birgi mehmet.birgi at wyona.com
Thu Jun 17 08:41:32 CEST 2010


Hi all

We recently had to implement some image scaling for a client project
where image quality is very important. After first trying the standard
tools that come with java.awt, since the results were not
satisfactory, we switched to the ImageMagick tool. We implemented IM
through the java interface im4java, and in the end, it worked just
fine.

The main difficulty was that the straightforward use of im4java needs
absolute file paths as input and output, as im4java is basically a
wrapper for the IM command line tool. Of course, this is not possible
to do through Yarep, as it breaks the decoupling of the repository
implementation. Luckily, we found out that im4java has an interface
that allows piping of input and output streams, that can be used as
follows:

        // create the operation, add images and operators/options
        IMOperation op = new IMOperation();
        op.addImage("-");
        op.resize(newWidth,newHeight);
        op.addImage("-");

        // create the pipes
        InputStream is = getRepoNodeInputStream(sourceImageRepoPath);
        Pipe pipeIn  = new Pipe(is, null);
        OutputStream os = getRepoNodeOutputStream(targetImageRepoPath);
        Pipe pipeOut = new Pipe(null, os);

        // execute the operation
        ConvertCmd cmd = new ConvertCmd();
        cmd.setInputProvider(pipeIn);
        cmd.setOutputConsumer(pipeOut);
        cmd.run(op);
        is.close();
        os.close();

I hope that this might be helpful if anybody else has the same problem.

Cheers,

Memo



-- 
Mehmet Birgi
www.wyona.com


More information about the Yanel-development mailing list