From 35827a56037a583eabea82708a801b7fc3f6d355 Mon Sep 17 00:00:00 2001
From: ulrich <not disclosed>
Date: Sun, 04 Mar 2018 13:25:08 +0000
Subject: [PATCH] Umgestellt auf Thumbnailator

---
 src/de/uhilger/wbx/web/TNServlet.java |   39 ++++++++++++++-------------------------
 1 files changed, 14 insertions(+), 25 deletions(-)

diff --git a/src/de/uhilger/wbx/web/TNServlet.java b/src/de/uhilger/wbx/web/TNServlet.java
index e86adb4..922fe89 100644
--- a/src/de/uhilger/wbx/web/TNServlet.java
+++ b/src/de/uhilger/wbx/web/TNServlet.java
@@ -17,20 +17,15 @@
  */
 package de.uhilger.wbx.web;
 
-import de.uhilger.wbx.Bild;
-import java.awt.Container;
-import java.awt.Image;
-import java.awt.MediaTracker;
-import java.awt.Toolkit;
 import java.io.File;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
-import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import net.coobird.thumbnailator.Thumbnails;
 import org.apache.catalina.servlets.DefaultServlet;
 
 /**
@@ -95,15 +90,15 @@
         
     if(uriStr.endsWith(JPG) || uriStr.endsWith(JPEG) || uriStr.endsWith(PNG)) {
       if(uriStr.contains(TN)) {
-        bildAusgeben(request, response, relname, TN, Bild.WINZIG);
+        bildAusgeben(request, response, relname, TN, 120);
       } else if(uriStr.contains(KL)) {
-        bildAusgeben(request, response, relname, KL, Bild.KLEIN);
+        bildAusgeben(request, response, relname, KL, 240);
       } else if(uriStr.contains(SM)) {
-        bildAusgeben(request, response, relname, SM, Bild.SEMI);
+        bildAusgeben(request, response, relname, SM, 500);
       } else if(uriStr.contains(MT)) {
-        bildAusgeben(request, response, relname, MT, Bild.MITTEL);
+        bildAusgeben(request, response, relname, MT, 700);
       } else if(uriStr.contains(GR)) {
-        bildAusgeben(request, response, relname, GR, Bild.GROSS);
+        bildAusgeben(request, response, relname, GR, 1200);
       } else {
         super.doGet(request, response);
       }      
@@ -112,22 +107,16 @@
     }
   }
   
-  private void bildAusgeben(HttpServletRequest request, HttpServletResponse response, String relname, String indicator, int bildTyp) throws UnsupportedEncodingException, IOException {
+  private void bildAusgeben(HttpServletRequest request, HttpServletResponse response, String relname, String indicator, int gr) throws UnsupportedEncodingException, IOException {
     File dir = new File(request.getServletContext().getRealPath("/"));
     relname = relname.replace(indicator, "");
     File imgfile = new File(dir, URLDecoder.decode(relname, "utf-8"));
-    Image image = Toolkit.getDefaultToolkit().getImage(imgfile.getAbsolutePath());
-    MediaTracker mediaTracker = new MediaTracker(new Container());
-    mediaTracker.addImage(image, 0);
-    try {
-      mediaTracker.waitForID(0);
+    
+    // 120, 240, 500, 700, 1200
 
-      if (!mediaTracker.isErrorAny()) {
-        Bild bild = new Bild();
-        bild.writeImageStream(image, bild.getVariantenGroesse(bildTyp), bild.getMimeType(imgfile), response.getOutputStream());
-      }
-    } catch (InterruptedException ex) {
-      logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
-    }
-  }
+    Thumbnails.of(imgfile)
+            .size(gr, gr)
+            .keepAspectRatio(true)
+            .toOutputStream(response.getOutputStream());
+  }  
 }

--
Gitblit v1.9.3