mirror of
https://github.com/sismics/docs.git
synced 2025-12-13 17:56:20 +00:00
Intermediate thumbnail size more web-friendly
This commit is contained in:
@@ -36,15 +36,19 @@ public class FileDeletedAsyncListener {
|
||||
|
||||
// Delete the file from storage
|
||||
File file = fileDeletedAsyncEvent.getFile();
|
||||
java.io.File thumbnailFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId() + "_thumb").toFile();
|
||||
java.io.File storedFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId()).toFile();
|
||||
java.io.File webFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId() + "_web").toFile();
|
||||
java.io.File thumbnailFile = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId() + "_thumb").toFile();
|
||||
|
||||
if (thumbnailFile.exists()) {
|
||||
thumbnailFile.delete();
|
||||
}
|
||||
if (storedFile.exists()) {
|
||||
storedFile.delete();
|
||||
}
|
||||
if (webFile.exists()) {
|
||||
webFile.delete();
|
||||
}
|
||||
if (thumbnailFile.exists()) {
|
||||
thumbnailFile.delete();
|
||||
}
|
||||
|
||||
// Update Lucene index
|
||||
LuceneDao luceneDao = new LuceneDao();
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.sismics.docs.core.util;
|
||||
|
||||
import java.awt.color.ColorSpace;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ColorConvertOp;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -55,8 +56,7 @@ public class FileUtil {
|
||||
}
|
||||
|
||||
// Upscale and grayscale the image
|
||||
BufferedImage resizedImage = Scalr.resize(image, Method.AUTOMATIC, Mode.AUTOMATIC, 3500,
|
||||
new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null));
|
||||
BufferedImage resizedImage = Scalr.resize(image, Method.AUTOMATIC, Mode.AUTOMATIC, 3500, Scalr.OP_ANTIALIAS, Scalr.OP_GRAYSCALE);
|
||||
image.flush();
|
||||
image = resizedImage;
|
||||
|
||||
@@ -71,4 +71,26 @@ public class FileUtil {
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a file on the storage filesystem.
|
||||
*
|
||||
* @param is InputStream
|
||||
* @param file File to save
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void save(InputStream is, File file) throws Exception {
|
||||
Path path = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId());
|
||||
Files.copy(is, path);
|
||||
|
||||
// In case of image, save thumbnails
|
||||
if (ImageUtil.isImage(file.getMimeType())) {
|
||||
BufferedImage image = ImageIO.read(path.toFile());
|
||||
BufferedImage web = Scalr.resize(image, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, 1280, Scalr.OP_ANTIALIAS);
|
||||
BufferedImage thumbnail = Scalr.resize(image, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, 256, Scalr.OP_ANTIALIAS);
|
||||
image.flush();
|
||||
ImageUtil.writeJpeg(web, Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId() + "_web").toFile());
|
||||
ImageUtil.writeJpeg(thumbnail, Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId() + "_thumb").toFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
package com.sismics.util;
|
||||
|
||||
import com.sismics.docs.core.model.jpa.File;
|
||||
import com.sismics.docs.core.util.DirectoryUtil;
|
||||
import org.imgscalr.Scalr;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* File utilities.
|
||||
*
|
||||
* @author bgamard
|
||||
*/
|
||||
public class FileUtil {
|
||||
|
||||
/**
|
||||
* Save a file on the storage filesystem.
|
||||
*
|
||||
* @param is InputStream
|
||||
* @param file File to save
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void save(InputStream is, File file) throws Exception {
|
||||
Path path = Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId());
|
||||
Files.copy(is, path);
|
||||
|
||||
// In case of image, save a thumbnail
|
||||
if (ImageUtil.isImage(file.getMimeType())) {
|
||||
BufferedImage image = ImageIO.read(path.toFile());
|
||||
BufferedImage resizedImage = Scalr.resize(image, Scalr.Method.AUTOMATIC, Scalr.Mode.AUTOMATIC, 256, Scalr.OP_ANTIALIAS);
|
||||
image.flush();
|
||||
ImageUtil.writeJpeg(resizedImage, Paths.get(DirectoryUtil.getStorageDirectory().getPath(), file.getId() + "_thumb").toFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user