use of org.structr.web.property.ThumbnailProperty in project structr by structr.
the class ImageHelper method findAndReconnectThumbnails.
public static void findAndReconnectThumbnails(final Image originalImage) {
final Class<Relation> thumbnailRel = StructrApp.getConfiguration().getRelationshipEntityClass("ImageTHUMBNAILImage");
final PropertyKey<Image> tnSmallKey = StructrApp.key(Image.class, "tnSmall");
final PropertyKey<Image> tnMidKey = StructrApp.key(Image.class, "tnMid");
final PropertyKey<String> pathKey = StructrApp.key(Image.class, "path");
final App app = StructrApp.getInstance();
final Integer origWidth = originalImage.getWidth();
final Integer origHeight = originalImage.getHeight();
if (origWidth == null || origHeight == null) {
if (!Arrays.asList("image/svg+xml", "image/x-icon", "image/x-photoshop").contains(originalImage.getContentType())) {
logger.info("Could not determine width and heigth for {}", originalImage.getName());
}
return;
}
for (ThumbnailProperty tnProp : new ThumbnailProperty[] { (ThumbnailProperty) tnSmallKey, (ThumbnailProperty) tnMidKey }) {
int maxWidth = tnProp.getWidth();
int maxHeight = tnProp.getHeight();
boolean crop = tnProp.getCrop();
final float scale = getScaleRatio(origWidth, origHeight, maxWidth, maxHeight, crop);
final String tnName = ImageHelper.getThumbnailName(originalImage.getName(), getThumbnailWidth(origWidth, scale), getThumbnailHeight(origHeight, scale));
try {
final Image thumbnail = (Image) app.nodeQuery(Image.class).and(pathKey, PathHelper.getFolderPath(originalImage.getProperty(pathKey)) + PathHelper.PATH_SEP + tnName).getFirst();
if (thumbnail != null) {
app.create(originalImage, thumbnail, thumbnailRel);
}
} catch (FrameworkException ex) {
logger.debug("Error reconnecting thumbnail " + tnName + " to original image " + originalImage.getName(), ex);
}
}
}
Aggregations