Added WebP thumbnail support
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 13 Mar 2021 02:56:50 +0000 (04:56 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sat, 13 Mar 2021 02:56:50 +0000 (04:56 +0200)
pom.xml
src/main/java/eu/svjatoslav/meviz/htmlindexer/Constants.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java

diff --git a/pom.xml b/pom.xml
index ff423bb..6101a94 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <artifactId>core-image</artifactId>
             <version>1.3.10</version>
         </dependency>
+        <dependency>
+            <groupId>org.sejda.imageio</groupId>
+            <artifactId>webp-imageio</artifactId>
+            <version>0.1.6</version>
+        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.scijava</groupId>-->
+<!--            <artifactId>native-lib-loader</artifactId>-->
+<!--            <version>2.3.5</version>-->
+<!--        </dependency>-->
     </dependencies>
 
     <distributionManagement>
index e8ef224..d302472 100755 (executable)
@@ -31,7 +31,7 @@ public class Constants {
             "E-mail: svjatoslav@svjatoslav.eu, homepage: http://svjatoslav.eu";
 
     public static final String[] SUPPORTED_IMAGE_EXTENSIONS = {
-            "jpg", "jpeg", "png", "gif"};
+            "jpg", "jpeg", "png", "gif", "webp"};
 
     public static final String[] SUPPORTED_VIDEO_EXTENSIONS = {
             "avi", "mp4", "mpeg", "mpg", "mkv", "flv", "ogv"};
index 075186e..e553c80 100755 (executable)
@@ -6,8 +6,10 @@
 
 package eu.svjatoslav.meviz.htmlindexer.indexer;
 
-import eu.svjatoslav.commons.file.IOHelper;
-import eu.svjatoslav.meviz.htmlindexer.*;
+import eu.svjatoslav.meviz.htmlindexer.CommandlineHandler;
+import eu.svjatoslav.meviz.htmlindexer.Constants;
+import eu.svjatoslav.meviz.htmlindexer.IndexingContext;
+import eu.svjatoslav.meviz.htmlindexer.Utils;
 import eu.svjatoslav.meviz.htmlindexer.layouts.Layout;
 import eu.svjatoslav.meviz.htmlindexer.metadata.Dimension;
 import eu.svjatoslav.meviz.htmlindexer.metadata.DirectoryMetadata;
@@ -22,6 +24,7 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 
+import static eu.svjatoslav.commons.file.IOHelper.overwriteFileIfContentDiffers;
 import static eu.svjatoslav.meviz.htmlindexer.Constants.THUMBNAILS_DIRECTORY_NAME;
 import static eu.svjatoslav.meviz.htmlindexer.Utils.getThumbnailsDirectoryPath;
 import static eu.svjatoslav.meviz.htmlindexer.Utils.urlEncode;
@@ -94,7 +97,7 @@ public class FilesystemIndexer extends AbstractIndexer {
 
                     compileHtml(layout, metadata);
 
-                    IOHelper.overwriteFileIfContentDiffers(indexFile, layout
+                    overwriteFileIfContentDiffers(indexFile, layout
                             .getHtml(true, true, metadata).getBytes());
                 }
             } catch (final Exception e) {
index 8b64bcd..64933e1 100755 (executable)
@@ -73,6 +73,8 @@ public class DirectoryMetadata implements Serializable {
             try {
                 return new Picture(parentDirectory, fileName);
             } catch (final Exception exception) {
+                System.out.println("Failed to decode image \"" + fileName +"\" indexing as normal file instead.");
+
                 // in case image decoding failed, handle image as general file
                 return new GeneralFile(parentDirectory, fileName);
             }
index 184bac6..50b39d5 100755 (executable)
@@ -166,8 +166,6 @@ public class Picture extends AbstractFile {
 
         System.out.println("Desired target image dimensions:" + targetDimensions);
 
-        FileInputStream fiStream = new FileInputStream(inputFile);
-
         ImageReader reader = ImageIO.getImageReadersByFormatName("gif").next();
         ImageInputStream stream = ImageIO.createImageInputStream(inputFile);
         reader.setInput(stream);
@@ -175,12 +173,12 @@ public class Picture extends AbstractFile {
         Utils.ImageFrame[] frames = Utils.readGIF(reader);
         for (Utils.ImageFrame frame : frames) {
             Image scaleImage = scaleImage(frame.image, targetDimensions.width, targetDimensions.height);
-            BufferedImage bimage = new BufferedImage(
+            BufferedImage bImage = new BufferedImage(
                     targetDimensions.width, targetDimensions.height, BufferedImage.TYPE_INT_ARGB);
-            Graphics2D bGr = bimage.createGraphics();
+            Graphics2D bGr = bImage.createGraphics();
             bGr.drawImage(scaleImage, 0, 0, null);
             bGr.dispose();
-            frame.image = bimage;
+            frame.image = bImage;
         }
 
         ImageOutputStream output = new FileImageOutputStream(outputFile);