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/pub/Catalog.java           |    2 
 /dev/null                                              |  181 ------------------------------------
 web/fotos/stile.css                                    |    2 
 web/ui/index.html                                      |    1 
 web/ui/api.js                                          |   12 ++
 web/fotos/index.html                                   |    4 
 src/java/de/uhilger/filecms/api/HtmlExportService.java |   20 ++-
 src/java/de/uhilger/filecms/api/FileMgr.java           |   63 +++++++++++-
 web/ui/ui.js                                           |    1 
 9 files changed, 90 insertions(+), 196 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(".")) {    
diff --git a/src/java/de/uhilger/filecms/api/HtmlExportService.java b/src/java/de/uhilger/filecms/api/HtmlExportService.java
index 8368466..56c726f 100644
--- a/src/java/de/uhilger/filecms/api/HtmlExportService.java
+++ b/src/java/de/uhilger/filecms/api/HtmlExportService.java
@@ -20,11 +20,7 @@
 
 package de.uhilger.filecms.api;
 
-import de.uhilger.filecms.data.Bild;
-import java.awt.Container;
-import java.awt.Image;
-import java.awt.MediaTracker;
-import java.awt.Toolkit;
+import de.uhilger.wbx.Bild;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileFilter;
@@ -34,6 +30,7 @@
 import java.io.PrintWriter;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+import net.coobird.thumbnailator.Thumbnails;
 import org.apache.commons.io.FileUtils;
 
 /**
@@ -190,6 +187,16 @@
           }
           String outFileName = new File(dir, tnFileName.toString()).getAbsolutePath();
           logger.fine("outFileName: " + outFileName);
+          
+        try {
+          Thumbnails.of(absPath)
+                  .size(bild.getVariantenGroesse(Bild.WINZIG), bild.getVariantenGroesse(Bild.WINZIG))
+                  .keepAspectRatio(true)
+                  .toFile(outFileName);
+        } catch (IOException ex) {
+          logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
+        }
+          /*
           Image image = Toolkit.getDefaultToolkit().getImage(absPath);
           MediaTracker mediaTracker = new MediaTracker(new Container());
           mediaTracker.addImage(image, 0);
@@ -203,7 +210,8 @@
             }
           } catch (InterruptedException | IOException ex) {
             logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
-          }      
+          } 
+          */
         }
       }
     } else {
diff --git a/src/java/de/uhilger/filecms/data/Bild.java b/src/java/de/uhilger/filecms/data/Bild.java
deleted file mode 100644
index 50b5eb3..0000000
--- a/src/java/de/uhilger/filecms/data/Bild.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
-    Dateiverwaltung - File management in your browser
-    Copyright (C) 2017 Ulrich Hilger, http://uhilger.de
-
-    This program is free software: you can redistribute it and/or modify
-    it under the terms of the GNU Affero General Public License as
-    published by the Free Software Foundation, either version 3 of the
-    License, or (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU Affero General Public License for more details.
-
-    You should have received a copy of the GNU Affero General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package de.uhilger.filecms.data;
-
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.RenderingHints;
-import java.awt.image.BufferedImage;
-import java.awt.image.ConvolveOp;
-import java.awt.image.Kernel;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.FileNameMap;
-import java.net.URLConnection;
-import javax.imageio.ImageIO;
-
-/**
- * Methoden zur Verkleinerung von Bildern
- */
-public class Bild {
-  
-  public static final int WINZIG = 0;
-  public static final int KLEIN = 1;
-  public static final int MITTEL = 2;
-  public static final int GROSS = 3;
-  
-  public static final String[] GRNAME = {"-w", "-k", "-m", "-g"};
-  public static final int[] GR = {120, 240, 700, 1200};
-  
-  public void writeImageStream(Image image, int gr, String mimeType, OutputStream out) throws InterruptedException, IOException {
-    ImageIO.write(getReducedImage(image, gr, mimeType), imgType(mimeType), out);
-  }
-  
-  /**
-   * 
-   * @param image
-   * @param gr
-   * @param mimeType
-   * @param vName Name der verkleinerten Datei
-   * @throws InterruptedException
-   * @throws IOException 
-   */
-  public void writeImageFile(Image image, int gr, String mimeType, String vName) throws InterruptedException, IOException {
-    ImageIO.write(getReducedImage(image, gr, mimeType), imgType(mimeType), new File(vName));
-  }
-  
-  private BufferedImage getReducedImage(Image image, int gr, String mimeType) throws InterruptedException, IOException {
-    BufferedImage img;
-    int q = 90;
-    float sh = 0.f;
-    if(mimeType.contains("jpeg")) {
-      img = getReducedImage(image, gr, gr, q, sh, false);
-    } else {
-      img = getReducedImage(image, gr, gr, q, sh, true);
-    }
-    return img;
-  }
-
-  /**
-   * Eine in Groesse und Qualitaet verringerte Bilddatei erzeugen
-   * @param image  Ablageort und Name der Bilddatei
-   * @param width  neue Breite
-   * @param height  neue hoehe
-   * @param quality neue Qualitaet (0 - 100)
-   * @param factor Faktor fuer Schaerfe / Unschaerfe (z.B. -0.15f fuer leichte Unschaerfe, 0.05f fuer leichtes Nachschaerfen)
-   * @param withTransparency ob Transparenz benoetigt wird
-   * @return neues, in Groesse und Qualitaet entsprechend verringertes Bild
-   * @throws java.lang.InterruptedException
-   * @throws java.io.FileNotFoundException
-   */
-  public BufferedImage getReducedImage(Image image, int width, int height, int quality, float factor, boolean withTransparency) 
-  throws InterruptedException, FileNotFoundException, IOException {
-
-    int imageWidth = image.getWidth(null);
-		int imageHeight = image.getHeight(null);
-
-  	int thumbWidth = width;
-		int thumbHeight = height;
-    if(imageWidth < width) {
-      thumbWidth = imageWidth;    
-    }
-    if(imageHeight < height) {
-      thumbHeight = imageHeight;
-    }
-		double thumbRatio = (double)thumbWidth / (double)thumbHeight;
-		double imageRatio = (double)imageWidth / (double)imageHeight;
-		if (thumbRatio < imageRatio) {
-			thumbHeight = (int)(thumbWidth / imageRatio);
-		}
-		else {
-			thumbWidth = (int)(thumbHeight * imageRatio);
-		}
-
-		// draw original image to thumbnail image object and
-		// scale it to the new size on-the-fly
-		//BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
-    BufferedImage thumbImage;
-    if(withTransparency) {
-  	  thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_ARGB);
-    } else {
-      thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
-    }
-		Graphics2D graphics2D = thumbImage.createGraphics();
-		graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
-		graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);
-
-		// 30.7.2007: sharpening hinzugefuegt (Anfang)
-		//float factor = -0.15f; // minus = sharpen, plus = soften
-		//float[] sharpenArray = {0, -1, 0, -1, 5, -1, 0, -1, 0};
-    
-    /*
-      30.6.2013: sharpening als Weichmacher nur, wenn Bild < 400
-    */
-    /*if(thumbWidth < 400 || thumbHeight < 400) {
-      factor = 0.1f;
-    }*/
-    
-		if(factor != 0.f) {
-			float[] array = {0, factor, 0, factor, 1-(factor*4), factor, 0, factor, 0};
-			Kernel kernel = new Kernel(3, 3, array);
-			ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null);
-			thumbImage = cOp.filter(thumbImage, null);
-		}
-		// 30.7.2007: sharpening hinzugefuegt (Ende)
-    
-    return thumbImage;
-  }
-  
-  public String imgType(String mimeType) {
-    String imgType;
-    if(mimeType.contains("jpg")) {
-      imgType = "jpg";
-    } else if(mimeType.contains("jpeg")) {
-      imgType = "jpg";
-    } else if(mimeType.contains("png")) {
-      imgType = "png";
-    } else if(mimeType.contains("gif")) {
-      imgType = "gif";
-    } else {
-      imgType = "jpg";
-    }
-    return imgType;
-  }
-  
-  /**
-   * 
-   * @param v Bild.WINZIG .. Bild.GROSS
-   * @return L&auml;nge der l&auml;ngsten Kante in Bildpunkten
-   */
-  public int getVariantenGroesse(int v) {
-    return GR[v];
-  }
-  
-  public String getVariantenName(int v) {
-    return GRNAME[v];
-  }
-  
-  public String getMimeType(File file) {
-    String absName = file.getAbsolutePath();
-    FileNameMap fileNameMap = URLConnection.getFileNameMap();
-    return fileNameMap.getContentTypeFor("file://" + absName);    
-  }
-}
diff --git a/src/java/de/uhilger/filecms/pub/Catalog.java b/src/java/de/uhilger/filecms/pub/Catalog.java
index 2e8153b..453049c 100644
--- a/src/java/de/uhilger/filecms/pub/Catalog.java
+++ b/src/java/de/uhilger/filecms/pub/Catalog.java
@@ -19,7 +19,7 @@
 package de.uhilger.filecms.pub;
 
 import de.uhilger.filecms.api.Api;
-import de.uhilger.filecms.data.Bild;
+import de.uhilger.wbx.Bild;
 import de.uhilger.filecms.data.FileRef;
 import java.io.File;
 import java.util.ArrayList;
diff --git a/web/fotos/index.html b/web/fotos/index.html
index 576f506..a605967 100644
--- a/web/fotos/index.html
+++ b/web/fotos/index.html
@@ -15,11 +15,11 @@
           {{#mini}}
             {{#dia}}
               <a href="{{bildurl}}" data-fancybox="group" data-caption="">
-                <img class="datei" src="{{miniurl}}"  width="60" height="40" />
+                <img class="datei" src="{{miniurl}}" />
               </a>
             {{/dia}}
             {{^dia}}
-              <img class="datei" src="{{miniurl}}"  width="60" height="40" />
+              <img class="datei" src="{{miniurl}}" />
             {{/dia}}
           {{/mini}}
           {{^mini}}
diff --git a/web/fotos/stile.css b/web/fotos/stile.css
index b636ae2..a6dbdc0 100644
--- a/web/fotos/stile.css
+++ b/web/fotos/stile.css
@@ -111,7 +111,7 @@
   -webkit-overflow-scrolling: touch;
 }
 .datei-figure {
-  width: 6em;
+  width: 8em;
   cursor: pointer;
 }
 
diff --git a/web/ui/api.js b/web/ui/api.js
index a875ef8..e1a7bb3 100644
--- a/web/ui/api.js
+++ b/web/ui/api.js
@@ -370,6 +370,18 @@
   });  
 }
 
+function fm_menu_rotate() {
+  var gewaehlte = $('.datei-gewaehlt');
+  var fname = $(gewaehlte[0]).text();
+  var m = '?c=de.uhilger.filecms.api.FileMgr&m=bildRotieren';
+  m = m + '&p=' + pfad; 
+  m = m + '&p=' + fname; 
+  var u = '../svc' + m;
+  fm_get(u, "text", function(resp) {
+    fm_get_list(pfad);
+  });  
+}
+
 /* -------- upload ----------- */
 
 function sendFile(datei) {
diff --git a/web/ui/index.html b/web/ui/index.html
index e82792b..fabf09f 100644
--- a/web/ui/index.html
+++ b/web/ui/index.html
@@ -113,6 +113,7 @@
               <a id="m-paste" class="dropdown-item" href="#">Einf&uuml;gen</a>
               <div class="dropdown-divider"></div>
               <a id="m-shrink" class="dropdown-item" href="#">Verkleinern</a>
+              <a id="m-rotate" class="dropdown-item" href="#">Rotieren</a>
               <div class="dropdown-divider"></div>
               <a id="m-del" class="dropdown-item" href="#">L&ouml;schen</a>
             </div>
diff --git a/web/ui/ui.js b/web/ui/ui.js
index c31fc2d..2ffaef4 100644
--- a/web/ui/ui.js
+++ b/web/ui/ui.js
@@ -66,6 +66,7 @@
   $('#m-copy').on('click', fm_menu_copy);
   $('#m-paste').on('click', fm_menu_paste);
   $('#m-shrink').on('click', fm_menu_shrink);
+  $('#m-rotate').on('click', fm_menu_rotate);
   $('#m-toggle-slideshow').on('click', fm_toggle_show_slideshow);
   $('#m-test').on('click', fm_menu_test);
   $('#m-test-2').on('click', fm_menu_compile);

--
Gitblit v1.9.3