use of org.olat.core.commons.services.thumbnail.CannotGenerateThumbnailException in project openolat by klemens.
the class MetaInfoFileImpl method getThumbnailInfo.
private Thumbnail getThumbnailInfo(int maxWidth, int maxHeight, boolean fill) {
for (Thumbnail thumbnail : thumbnails) {
if (maxHeight == thumbnail.getMaxHeight() && maxWidth == thumbnail.getMaxWidth()) {
if (thumbnail.exists()) {
return thumbnail;
}
}
}
// generate a file name
File metaLoc = metaFile.getParentFile();
String name = originFile.getName();
String extension = FileUtils.getFileSuffix(name);
String nameOnly = name.substring(0, name.length() - extension.length() - 1);
String randuuid = UUID.randomUUID().toString();
String thumbnailExtension = preferedThumbnailType(extension);
File thumbnailFile = new File(metaLoc, nameOnly + "_" + randuuid + "_" + maxHeight + "x" + maxWidth + (fill ? "xfill" : "") + "." + thumbnailExtension);
// generate thumbnail
long start = 0l;
if (log.isDebug())
start = System.currentTimeMillis();
VFSLeaf thumbnailLeaf = new LocalFileImpl(thumbnailFile);
VFSLeaf originLeaf = new LocalFileImpl(originFile);
if (thumbnailService != null && thumbnailService.isThumbnailPossible(thumbnailLeaf)) {
try {
if (thumbnails.isEmpty()) {
// be paranoid
cannotGenerateThumbnail = true;
write();
}
log.info("Start thumbnail: " + thumbnailLeaf);
FinalSize finalSize = thumbnailService.generateThumbnail(originLeaf, thumbnailLeaf, maxWidth, maxHeight, fill);
if (finalSize == null) {
return null;
} else {
Thumbnail thumbnail = new Thumbnail();
thumbnail.setMaxHeight(maxHeight);
thumbnail.setMaxWidth(maxWidth);
thumbnail.setFinalHeight(finalSize.getHeight());
thumbnail.setFinalWidth(finalSize.getWidth());
thumbnail.setFill(true);
thumbnail.setThumbnailFile(thumbnailFile);
thumbnails.add(thumbnail);
cannotGenerateThumbnail = false;
write();
log.info("Create thumbnail: " + thumbnailLeaf);
if (log.isDebug()) {
log.debug("Creation of thumbnail takes (ms): " + (System.currentTimeMillis() - start));
}
return thumbnail;
}
} catch (CannotGenerateThumbnailException e) {
// don't try every time to create the thumbnail.
cannotGenerateThumbnail = true;
write();
return null;
}
}
return null;
}
Aggregations