From 438b168cad54853a8b419e6c19e639b6d2f70bc0 Mon Sep 17 00:00:00 2001
From: ulrich <undisclosed>
Date: Wed, 08 Mar 2017 06:42:10 +0000
Subject: [PATCH] Bild verkleinern (in Arbeit)

---
 src/java/de/uhilger/filecms/api/FileMgr.java |   51 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/src/java/de/uhilger/filecms/api/FileMgr.java b/src/java/de/uhilger/filecms/api/FileMgr.java
index 840a223..3e1073c 100644
--- a/src/java/de/uhilger/filecms/api/FileMgr.java
+++ b/src/java/de/uhilger/filecms/api/FileMgr.java
@@ -20,13 +20,16 @@
 
 import de.uhilger.filecms.data.FileRef;
 import de.uhilger.filecms.web.Initialiser;
+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.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.InputStreamReader;
 import java.io.Reader;
 import java.security.Principal;
 import java.util.ArrayList;
@@ -35,7 +38,6 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang.StringEscapeUtils;
 
 /**
  *
@@ -299,7 +301,50 @@
     }
     return savedFile;
   }
+  
+  public String bildVerkleinern(String relPath, String bildName) {
+    File dir = getTargetDir(relPath);
+    File original = new File(dir, bildName);
+    Bild bild = new Bild();
+    //for (int i = 0; i < Bild.GR.length; i++) {
     
+      //int gr = bild.getVariantenGroesse(i);
+      
+      String ext = "";
+      String nurname = bildName;
+      int dotpos = bildName.indexOf(".");
+      if (dotpos > -1) {
+        ext = bildName.substring(dotpos);
+        nurname = bildName.substring(0, dotpos);
+      }
+        
+      Image image = Toolkit.getDefaultToolkit().getImage(original.getAbsolutePath());
+      MediaTracker mediaTracker = new MediaTracker(new Container());
+      mediaTracker.addImage(image, 0);
+      try {
+        mediaTracker.waitForID(0);
+
+        if(!mediaTracker.isErrorAny()) {
+          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());
+            if(!newImgFile.exists()) {
+              logger.fine(original.getAbsolutePath() + " " + newImgFile.getAbsolutePath());
+              bild.writeImageFile(image, bild.getVariantenGroesse(i), bild.getMimeType(original), original.getAbsolutePath(), newImgFile.getAbsolutePath());
+              //bild.writeImageFile(image, photo.getVariantenGroesse(i), photo.getMimetype(), photo.getAbsolutePath(basisPfad), photo.getVariantenName(basisPfad, i));
+            }
+          }
+        }
+      } catch(IOException | InterruptedException ex) {
+        logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
+      }
+
+    return "ok";
+  }
+
   /* ---- Hilfsfunktionen ---- */
   
   private File getTargetDir(String relPath) {

--
Gitblit v1.9.3