Helo Friends,

I have 1000s of image files(jpg/png) which I want to get compressed so as to reduce the file size. Quality can be compromised a bit.
I want to know, is there any way in java by which I can get the image compressed?

I found a code on internet for compression which uses ImageWriterParam class, but the problem is that - instead of reducing, it increases the size of the new image.

Please guide me in this context. If, possible, please tell me where can I get code for the same.

Thank You.

convert them all to gif?

With a jpeg image, you can play with "compression level", of course, but this also effects quality. png are not "compressed" at all (as png is gif without the compression routines). So, convert them to gif, and they will get smaller. If you say you can't, then you're stuck.

Is it possible to compress an image before saving it?
I'm using the Robot class to capture images, and it returns a bufferedImage.
How can I compress this image and then save it?

Please help.

import javaQuery.j2ee.ImageResize;
    public class imagetest {
        public static void main(String[] args) {
            ImageResize ir = new ImageResize();
            ir.compressImage("c:\\test.JPG", 300, 300);
        }
    }

Image Resize ir = new ImageResize();
ir.compressImage("FileLink", width, height);

Note: If you don't want to change width and height then set width = 0 and height = 0 . It'll compress image with original width and height (Compress File size).

Download API

This article has been dead for over six months. Start a new discussion instead.