import com.imageresize4j.ImageResizeProcessor;

import javax.imageio.ImageIO;
import javax.imageio.ImageWriter;
import javax.imageio.ImageWriteParam;
import javax.imageio.IIOImage;
import javax.imageio.stream.FileImageOutputStream;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
 * ImageResize4J SHARP_LIGHT_5 Resize Example
 */
public class IR4JImageResizeExample {

    public static void main(String[] args) {
        try {
            BufferedImage source = ImageIO.read(new File(args[0]));
            int destWidth = Integer.parseInt(args[1]);
            int destHeight = 0;
            if (args.length == 3)
                destHeight = Integer.parseInt(args[2]);
            ImageResizeProcessor processor = new ImageResizeProcessor(ImageResizeProcessor.TYPE_SHARP_LIGHT_5);
            writeJPEG(processor.resize(source, destWidth, destHeight)"C:\\output.jpg");
        catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void writeJPEG(BufferedImage input, String namethrows IOException {
        Iterator iter =
                ImageIO.getImageWritersByFormatName("JPG");
        if (iter.hasNext()) {
            ImageWriter writer = (ImageWriteriter.next();
            ImageWriteParam iwp =
                    writer.getDefaultWriteParam();
            iwp.setCompressionMode(
                    ImageWriteParam.MODE_EXPLICIT);
            iwp.setCompressionQuality(0.95f);
            File outFile = new File(name);
            FileImageOutputStream output =
                    new FileImageOutputStream(outFile);
            writer.setOutput(output);
            IIOImage image =
                    new IIOImage(input, null, null);
            writer.write(null, image, iwp);
            output.close();
        }
    }
}
Java2html