From ef718ada685feafaacaa498f2f128731ed019d58 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sat, 13 Mar 2021 04:56:50 +0200 Subject: [PATCH] Added WebP thumbnail support --- pom.xml | 10 ++++++++++ .../eu/svjatoslav/meviz/htmlindexer/Constants.java | 2 +- .../meviz/htmlindexer/indexer/FilesystemIndexer.java | 9 ++++++--- .../meviz/htmlindexer/metadata/DirectoryMetadata.java | 2 ++ .../meviz/htmlindexer/metadata/fileTypes/Picture.java | 8 +++----- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index ff423bb..6101a94 100644 --- a/pom.xml +++ b/pom.xml @@ -151,6 +151,16 @@ core-image 1.3.10 + + org.sejda.imageio + webp-imageio + 0.1.6 + + + + + + diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Constants.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Constants.java index e8ef224..d302472 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/Constants.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/Constants.java @@ -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"}; diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java index 075186e..e553c80 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/indexer/FilesystemIndexer.java @@ -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) { diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java index 8b64bcd..64933e1 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/DirectoryMetadata.java @@ -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); } diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java index 184bac6..50b39d5 100755 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/Picture.java @@ -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); -- 2.20.1