From 51ca668d316d8b4d284a255ac9b28c112f9f2690 Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Mon, 15 Jan 2018 17:17:53 +0000
Subject: [PATCH] ..

---
 src/bilder.groovy |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/bilder.groovy b/src/bilder.groovy
index 7a14ff1..00ce2a1 100644
--- a/src/bilder.groovy
+++ b/src/bilder.groovy
@@ -14,14 +14,17 @@
 import java.net.FileNameMap;
 import java.net.URLConnection;
 import javax.imageio.ImageIO;
+import javax.imageio.ImageWriter;
+import javax.imageio.ImageWriteParam;
+import javax.imageio.stream.FileImageOutputStream;
+import javax.imageio.IIOImage;
 import java.lang.Integer;
 
 /*
-	Skript zum Verkleinern von Bildern mit Hilfe
-	der Klasse Bild
+	Java-Code zum Verkleinern von Bildern
 
 	args[0] - Anzahl Pixel an der laengsten Kante
-	args[1] - qualitaet JPEG, z.B. 75 fuer 75%
+	args[1] - qualitaet JPEG, z.B. 0.75 fuer 75% des Originals
 	args[2] - Eingangsordner
 	args[3] - Ausgabeordner
 */
@@ -47,7 +50,7 @@
       mediaTracker.waitForID(0);
       if (!mediaTracker.isErrorAny()) {
 
-        int quality = Integer.parseInt(args[1]);
+        float quality = Float.parseFloat(args[1]);
         float factor = (float) 0.0;
 
         BufferedImage thumbImage;
@@ -124,12 +127,22 @@
           imgType = "jpg";
         }
 
-        ImageIO.write(thumbImage, imgType, outFile);
+				/*
+					14.1.2018: Ausgabe um Qualitaetsparameter erweitert
+					Beginn
+				*/
+        ImageWriter writer = ImageIO.getImageWritersByFormatName(imgType).next();
+        ImageWriteParam iwp = writer.getDefaultWriteParam();
+        iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
+        iwp.setCompressionQuality(quality);
+        writer.setOutput(new FileImageOutputStream(outFile));
+        writer.write(null, new IIOImage(thumbImage, null, null), iwp);
+        writer.dispose();
+				/* 14.1.2018 Ende */
       }
     } catch (InterruptedException ex) {
       System.out.println("Error: " + ex.getLocalizedMessage());
     }
-
 	}
 } else {
 	System.out.println("fileList is null or empty");

--
Gitblit v1.9.3