import eu.svjatoslav.meviz.htmlindexer.Utils;
import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
-import javax.imageio.ImageIO;
-import javax.imageio.ImageReader;
+import javax.imageio.*;
import javax.imageio.stream.FileImageOutputStream;
import javax.imageio.stream.ImageInputStream;
import javax.imageio.stream.ImageOutputStream;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
-import java.io.*;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import static eu.svjatoslav.meviz.htmlindexer.Utils.getBufferedImage;
final java.awt.Dimension targetDimensions = getTargetThumbnailDimension(
sourceImageDimension, preferredTargetDimensions);
- final OutputStream out = new FileOutputStream(outputFile);
final Image scaledImage = scaleImage(inputImage,
targetDimensions.width, targetDimensions.height);
g.drawImage(scaledImage, 0, 0, null);
g.dispose();
- ImageIO.write(bufferedImage, "webp", out);
- out.close();
+
+
+ ImageOutputStream ios = ImageIO.createImageOutputStream(outputFile);
+ Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("webp");
+ ImageWriter writer = iter.next();
+ ImageWriteParam iwp = writer.getDefaultWriteParam();
+ iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
+ iwp.setCompressionType("Lossy");
+ iwp.setCompressionQuality(0.8f);
+
+ writer.setOutput(ios);
+ writer.write(null, new IIOImage(bufferedImage,null,null),iwp);
+ writer.dispose();
}
private static void makeGifThumbnail(