/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright 2013 Redwarp
 */

package net.redwarp.tool.resizer.worker;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * User: benoit.vermont@airtag.com
 * Date: 28/10/14
 * Time: 19:24
 */
public class ImageWriter {
    public static void write(BufferedImage outputImage, Output output, File outputFile) throws IOException {
        if (output == Output.JPG) {
            // Need to strip alpha;
            BufferedImage img = new BufferedImage(outputImage.getWidth(), outputImage.getHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = img.createGraphics();
            g2d.drawImage(outputImage, 0, 0, null);
            g2d.dispose();
            outputImage = img;
        }

        ImageIO.write(outputImage, output.getFormat(), outputFile);
    }
}

@@ -649,22 +649,142 @@
 mageio.I
-mageIO
+IOImage;%0Aimport javax.imageio.ImageIO;%0Aimport javax.imageio.ImageWriteParam;%0Aimport javax.imageio.stream.FileImageOutputStream
 ;%0Aimport
@@ -881,16 +881,43 @@
 ception;
+%0Aimport java.util.Iterator;
 %0A%0A/**%0A *
@@ -1483,24 +1483,25 @@
  = img;%0A
+%0A
         
 %7D%0A%0A     
@@ -1496,11 +1496,682 @@
     
-%7D%0A%0A
+    Iterator%3Cjavax.imageio.ImageWriter%3E itor = ImageIO.getImageWritersByFormatName(%22jpeg%22);%0A            javax.imageio.ImageWriter writer = itor.next();%0A            ImageWriteParam imageWriteParam = writer.getDefaultWriteParam();%0A            imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);%0A            imageWriteParam.setCompressionQuality(0.9f);%0A%0A            FileImageOutputStream outputStream = new FileImageOutputStream(outputFile);%0A            writer.setOutput(outputStream);%0A            IIOImage image = new IIOImage(outputImage, null, null);%0A            writer.write(null, image, imageWriteParam);%0A            writer.dispose();%0A%0A        %7D else %7B%0A    
     
@@ -2230,20 +2230,30 @@
 utputFile);%0A
+        %7D%0A
     %7D%0A%7D%0A

Set compression for jpg to 0.9