tags:

views:

662

answers:

4

Is there some library in Java to compress Png images like pngout, pngcrush, optipng which are written in C/C++?

In continuation to what Phil has commented below, what I meant was reducing the file size of the image generated by the ImageIO class in Java by removing information that is not needed, same as what pngout does. When I ran pngout on the images that were generated by ImageIO class I was able to get about 50% reduction in file size (reduction size will vary based on images). So I wanted to know if there is any tool or library that could be interfaced with Java so that image files produced ImageIO class can have their size reduced.

+1  A: 

You could call an executable from Java to do the work, or you could wrap the library using SWIG and call it from Java.

justinhj
A: 

JMagick provides an object-oriented Java interface to ImageMagick.

ImageMagick® is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to translate, flip, mirror, rotate, scale, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.

lothar
A: 

PNG uses a lossless compression algorithm, so you cannot further compress a PNG file and expect to get much smaller files (they may just get slightly bigger).

  • If you need a lower resolution, then resize the image and recompress.
  • If you don't mind losing detail and degrading the image, then convert to JPG.
  • If your image always contains very simple shapes and colours, like cartoons, then consider GIF files instead.

JMagick, as lothar mentioned, will be able to perform all of these actions.

Phil H
pngout doesn't apply more compression, it removes "unnecessary" information from the PNG file: http://www.codinghorror.com/blog/archives/000810.html
Chris Zwiryk
Chris: And? The question was "Is there some library in Java to compress Png images", which implied that the asker didn't know what was happening with pngout. Pngout will also not significantly reduce the size - in that codinghorror article, it manages an additional 10%. Switching to lossy and/or resizing the image can chop it by any amount, 90% if you want.
Phil H
A: 

If you had tried pngout (http://advsys.net/ken/utils.htm#pngout) it actually reduces the file size without reducing the quality, that is what I require. Maybe I should try what justinhj has mentioned

Ram