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

---
 src/java/de/uhilger/filecms/api/FileMgr.java |   63 +++++++++++++++++++++++++++++--
 1 files changed, 58 insertions(+), 5 deletions(-)

diff --git a/src/java/de/uhilger/filecms/api/FileMgr.java b/src/java/de/uhilger/filecms/api/FileMgr.java
index 8e63002..fba0d22 100644
--- a/src/java/de/uhilger/filecms/api/FileMgr.java
+++ b/src/java/de/uhilger/filecms/api/FileMgr.java
@@ -18,14 +18,10 @@
 
 package de.uhilger.filecms.api;
 
-import de.uhilger.filecms.data.Bild;
 import de.uhilger.filecms.data.FileRef;
 import de.uhilger.filecms.pub.AbstractComparator;
 import de.uhilger.filecms.pub.FileNameComparator;
-import java.awt.Container;
-import java.awt.Image;
-import java.awt.MediaTracker;
-import java.awt.Toolkit;
+import de.uhilger.wbx.Bild;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
@@ -44,6 +40,7 @@
 import java.util.logging.Logger;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
+import net.coobird.thumbnailator.Thumbnails;
 import org.apache.commons.io.FileUtils;
 
 /**
@@ -385,6 +382,25 @@
         nurname = bildName.substring(0, dotpos);
       }
 
+          // 120, 240, 500, 700, 1200
+
+      
+      for (int i = 0; i < Bild.GR.length; i++) {
+        StringBuffer buf = new StringBuffer();
+        buf.append(nurname);
+        buf.append(bild.getVariantenName(i));
+        buf.append(ext);
+        File newImgFile = new File(dir, buf.toString());
+        try {
+          Thumbnails.of(original)
+                  .size(bild.getVariantenGroesse(i), bild.getVariantenGroesse(i))
+                  .keepAspectRatio(true)
+                  .toFile(newImgFile);
+        } catch (IOException ex) {
+          logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
+        }
+      }
+      /*
       Image image = Toolkit.getDefaultToolkit().getImage(original.getAbsolutePath());
       MediaTracker mediaTracker = new MediaTracker(new Container());
       mediaTracker.addImage(image, 0);
@@ -408,12 +424,49 @@
       } catch (IOException | InterruptedException ex) {
         logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
       }
+      */
       return "ok";
     } else {
       return "Pfad micht erlaubt.";
     }
   }
   
+  public String bildRotieren(String relPath, String bildName) {
+    if (!relPath.startsWith(".")) {
+      File dir = getTargetDir(relPath);
+      File original = new File(dir, bildName);
+
+      String ext = "";
+      String nurname = bildName;
+      int dotpos = bildName.indexOf(".");
+      if (dotpos > -1) {
+        ext = bildName.substring(dotpos);
+        nurname = bildName.substring(0, dotpos);
+      }
+
+      StringBuffer buf = new StringBuffer();
+      buf.append(nurname);
+      buf.append("-rot");
+      buf.append(ext);
+      File newImgFile = new File(dir, buf.toString());
+      
+      logger.fine("original: " + original.getAbsolutePath() + " newImgFile: " + newImgFile.getAbsolutePath());
+
+      try {
+        Thumbnails.of(original)
+                .scale(1)
+                .rotate(90)
+                .toFile(newImgFile);
+      } catch (IOException ex) {
+        logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
+      }
+
+
+      return "ok";
+    } else {
+      return "Pfad micht erlaubt.";
+    }
+  }
   public String extractZipfile(String relPath, String filename) {
     String result = null;
     if (!relPath.startsWith(".")) {    

--
Gitblit v1.9.3