Search in sources :

Example 1 with ThumbnailProperty

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);
        }
    }
}
Also used : StructrApp(org.structr.core.app.StructrApp) App(org.structr.core.app.App) ThumbnailProperty(org.structr.web.property.ThumbnailProperty) FrameworkException(org.structr.common.error.FrameworkException) BufferedImage(java.awt.image.BufferedImage) Image(org.structr.web.entity.Image) Relation(org.structr.core.entity.Relation)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1 FrameworkException (org.structr.common.error.FrameworkException)1 App (org.structr.core.app.App)1 StructrApp (org.structr.core.app.StructrApp)1 Relation (org.structr.core.entity.Relation)1 Image (org.structr.web.entity.Image)1 ThumbnailProperty (org.structr.web.property.ThumbnailProperty)1