Commit 7b5ca80e authored by Matija Obreza's avatar Matija Obreza

Merge branch 'server-446-better-thumbnail-quality' into 'master'

Improved generating of thumbnails

Closes genesys-server#446

See merge request !31
parents c9d5e0cc 76201839
Pipeline #10115 failed with stage
in 1 minute
......@@ -19,6 +19,7 @@ package org.genesys.filerepository.service.impl;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
......@@ -253,9 +254,9 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
imageGallery2.getImages().forEach(repositoryImage -> {
try {
final byte[][] cache = new byte[1][];
for (int thumbSize: thumbnailSizes) {
ensureThumbnail(thumbSize, thumbSize, repositoryImage, () -> {
for (int i = thumbnailSizes.length - 1; i >= 0; i--) {
cache[0] = ensureThumbnail(thumbnailSizes[i], thumbnailSizes[i], repositoryImage, () -> {
if (cache[0] != null) {
LOG.debug("Using cached image bytes for {}", repositoryImage.getStoragePath());
return cache[0];
......@@ -318,7 +319,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
* @throws IOException Signals that an I/O exception has occurred.
* @throws InvalidRepositoryPathException if path is messed up
*/
private void ensureThumbnail(final Integer width, final Integer height, final RepositoryImage repositoryImage, final IImageBytesProvider loader) throws IOException, InvalidRepositoryPathException {
private byte[] ensureThumbnail(final Integer width, final Integer height, final RepositoryImage repositoryImage, final IImageBytesProvider loader) throws IOException, InvalidRepositoryPathException {
final String filename = getThumbnailFilename(width, height, repositoryImage.getUuid());
if (!bytesStorageService.exists(getFullThumbnailsPath(repositoryImage).resolve(filename))) {
......@@ -331,11 +332,12 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
LOG.debug("Persisting new thumbnail width={} height={} for image={}", width, height, repositoryImage.getUuid());
bytesStorageService.upsert(getFullThumbnailsPath(repositoryImage).resolve(filename), bytesPng);
return bytesPng;
} catch (NullPointerException e) {
LOG.warn("Error generating thumbnail: {}", e.getMessage());
}
}
return null;
}
/**
......@@ -400,6 +402,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
}
public void setThumbnailSizes(int[] thumbnailSizes) {
Arrays.sort(thumbnailSizes);
this.thumbnailSizes = thumbnailSizes;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment