Index: api/src/main/java/org/hippoecm/frontend/plugins/gallery/model/GalleryProcessor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- api/src/main/java/org/hippoecm/frontend/plugins/gallery/model/GalleryProcessor.java (revision 48057) +++ api/src/main/java/org/hippoecm/frontend/plugins/gallery/model/GalleryProcessor.java (revision ) @@ -1,5 +1,5 @@ /* - * Copyright 2009-2013 Hippo B.V. (http://www.onehippo.com) + * Copyright 2009-2015 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,8 @@ import java.awt.Dimension; import java.io.InputStream; import java.util.Calendar; - +import java.util.Map; +import org.hippoecm.frontend.plugins.gallery.imageutil.ScalingParameters; import javax.jcr.Node; import javax.jcr.RepositoryException; @@ -37,5 +38,8 @@ public Dimension getDesiredResourceDimension(Node node) throws GalleryException, RepositoryException; public boolean isUpscalingEnabled(Node node) throws GalleryException, RepositoryException; + + public Map getScalingParametersMap() throws RepositoryException; + } Index: gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessor.java (revision 48057) +++ gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessor.java (revision ) @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Hippo B.V. (http://www.onehippo.com) + * Copyright 2010-2015 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,7 @@ import org.apache.jackrabbit.JcrConstants; import org.hippoecm.frontend.editor.plugins.resource.ResourceHelper; import org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperation; +import org.hippoecm.frontend.plugins.gallery.imageutil.ScalingParameters; import org.hippoecm.frontend.plugins.gallery.model.GalleryException; import org.hippoecm.repository.gallery.HippoGalleryNodeType; import org.slf4j.Logger; @@ -126,6 +127,7 @@ int height = scaleOperation.getHeight(); return new Dimension(width, height); } else { + log.warn("No scaling parameters found for: {}.",nodeName); return null; } } @@ -134,5 +136,10 @@ String nodeName = resource.getName(); ScalingParameters scaleOperation = scalingParametersMap.get(nodeName); return scaleOperation == null || scaleOperation.getUpscaling(); + } + + @Override + public Map getScalingParametersMap() { + return scalingParametersMap; } } Index: api/src/main/java/org/hippoecm/frontend/plugins/gallery/model/DefaultGalleryProcessor.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- api/src/main/java/org/hippoecm/frontend/plugins/gallery/model/DefaultGalleryProcessor.java (revision 48057) +++ api/src/main/java/org/hippoecm/frontend/plugins/gallery/model/DefaultGalleryProcessor.java (revision ) @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 Hippo B.V. (http://www.onehippo.com) + * Copyright 2008-2015 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,9 @@ import java.io.IOException; import java.io.InputStream; import java.util.Calendar; +import java.util.HashMap; import java.util.Iterator; +import java.util.Map; import javax.imageio.ImageIO; import javax.imageio.ImageReader; @@ -44,6 +46,7 @@ import org.hippoecm.frontend.editor.plugins.resource.ResourceException; import org.hippoecm.frontend.editor.plugins.resource.ResourceHelper; import org.hippoecm.frontend.model.JcrHelper; +import org.hippoecm.frontend.plugins.gallery.imageutil.ScalingParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -355,5 +358,10 @@ @Override public boolean isUpscalingEnabled(Node node) throws GalleryException, RepositoryException { return true; + } + + @Override + public Map getScalingParametersMap() { + return new HashMap(); } } Index: gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/editor/ImageCropEditorDialog.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/editor/ImageCropEditorDialog.java (revision 48057) +++ gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/editor/ImageCropEditorDialog.java (revision ) @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 Hippo B.V. (http://www.onehippo.com) + * Copyright 2011-2015 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,6 +50,8 @@ import org.hippoecm.frontend.plugins.gallery.editor.crop.ImageCropBehavior; import org.hippoecm.frontend.plugins.gallery.editor.crop.ImageCropSettings; import org.hippoecm.frontend.plugins.gallery.imageutil.ImageUtils; +import org.hippoecm.frontend.plugins.gallery.imageutil.ScaleImageOperation; +import org.hippoecm.frontend.plugins.gallery.imageutil.ScalingParameters; import org.hippoecm.frontend.plugins.gallery.model.GalleryException; import org.hippoecm.frontend.plugins.gallery.model.GalleryProcessor; import org.hippoecm.frontend.plugins.standards.image.JcrImage; @@ -77,6 +79,7 @@ private Dimension originalImageDimension; private Dimension configuredDimension; private Dimension thumbnailDimension; + private float compressionQuality; public ImageCropEditorDialog(IModel jcrImageNodeModel, GalleryProcessor galleryProcessor) { super(jcrImageNodeModel); @@ -157,7 +160,14 @@ new StringResourceModel("preview-description-enabled", this, null) : new StringResourceModel("preview-description-disabled", this, null)) ); + + compressionQuality = 1.0f; + try{ + compressionQuality = galleryProcessor.getScalingParametersMap().get(thumbnailImageNode.getName()).getCompressionQuality(); + } catch (RepositoryException e) { + log.info("Cannot retrieve compression quality.", e); } + } /** * Determine the scaling factor of the preview image, so that it fits within the max boundaries of @@ -237,10 +247,27 @@ } BufferedImage thumbnail = ImageUtils.scaleImage(original, left, top, width, height, (int) dimension.getWidth(), (int) dimension.getHeight(), hints, highQuality); - ByteArrayOutputStream bytes = ImageUtils.writeImage(writer, thumbnail); + ByteArrayOutputStream bytes = ImageUtils.writeImage(writer, thumbnail, compressionQuality); + //CMS7-8544 Keep the scaling of the image when cropping, to avoid a resulting image with bigger size than the original + InputStream stored = new ByteArrayInputStream(bytes.toByteArray()); + final ScalingParameters parameters = galleryProcessor.getScalingParametersMap().get(getModelObject().getName()); + if (parameters != null) { + try { + final ScaleImageOperation scaleOperation = new ScaleImageOperation(parameters.getWidth(), parameters.getHeight(), + parameters.getUpscaling(), parameters.getStrategy(), parameters.getCompressionQuality()); + scaleOperation.execute(stored, mimeType); + stored = scaleOperation.getScaledData(); + } catch (GalleryException e) { + log.warn("Scaling failed, using original image instead", e); + } + } else { + log.debug("No scaling parameters specified for {}, using original image", galleryProcessor.getScalingParametersMap().get(getModelObject().getName())); + } + + final Node cropped = getModelObject(); - cropped.setProperty(JcrConstants.JCR_DATA, newBinaryFromBytes(cropped, bytes)); + cropped.setProperty(JcrConstants.JCR_DATA, ResourceHelper.getValueFactory(cropped).createBinary(stored));//newBinaryFromBytes(cropped, bytes)); cropped.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance()); cropped.setProperty(HippoGalleryNodeType.IMAGE_WIDTH, dimension.getWidth()); cropped.setProperty(HippoGalleryNodeType.IMAGE_HEIGHT, dimension.getHeight()); Index: gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessorPlugin.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessorPlugin.java (revision 48057) +++ gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingGalleryProcessorPlugin.java (revision ) @@ -23,13 +23,14 @@ import org.hippoecm.frontend.plugin.Plugin; import org.hippoecm.frontend.plugin.config.IPluginConfig; import org.hippoecm.frontend.plugins.gallery.imageutil.ImageUtils; +import org.hippoecm.frontend.plugins.gallery.imageutil.ScalingParameters; import org.hippoecm.frontend.plugins.gallery.model.GalleryProcessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** *

- * Registers a {@link ScalingGalleryProcessor} and initializes the {@link ScalingParameters} for each scaled image. + * Registers a {@link ScalingGalleryProcessor} and initializes the {@link org.hippoecm.frontend.plugins.gallery.imageutil.ScalingParameters} for each scaled image. * Configuration of the scaling parameters of each image is done in a child node of type frontend:plugconfig with * a name equal to the node name of the image. Each node can contain integer properties for the width and height, and * a boolean property for the upscaling setting. It is also possible to configured the scaling strategy to use in Index: gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingParameters.java =================================================================== --- gallery/frontend/src/main/java/org/hippoecm/frontend/plugins/gallery/processor/ScalingParameters.java (revision 48057) +++ api/src/main/java/org/hippoecm/frontend/plugins/gallery/imageutil/ScalingParameters.java (revision ) @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 Hippo B.V. (http://www.onehippo.com) + * Copyright 2010-2015 Hippo B.V. (http://www.onehippo.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,11 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.hippoecm.frontend.plugins.gallery.processor; +package org.hippoecm.frontend.plugins.gallery.imageutil; import java.io.Serializable; - -import org.hippoecm.frontend.plugins.gallery.imageutil.ImageUtils; /** * Parameters for a scaling operation: the width and height of the bounding box, and whether to do