diff --git a/config/alfresco/rendition-services-context.xml b/config/alfresco/rendition-services-context.xml index a56d83da6e..1184337039 100644 --- a/config/alfresco/rendition-services-context.xml +++ b/config/alfresco/rendition-services-context.xml @@ -142,6 +142,7 @@ + diff --git a/source/java/org/alfresco/repo/content/transform/magick/ImageCropOptions.java b/source/java/org/alfresco/repo/content/transform/magick/ImageCropOptions.java index 590696e502..ca229e52d9 100644 --- a/source/java/org/alfresco/repo/content/transform/magick/ImageCropOptions.java +++ b/source/java/org/alfresco/repo/content/transform/magick/ImageCropOptions.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2010 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -19,162 +19,15 @@ package org.alfresco.repo.content.transform.magick; +import org.alfresco.service.cmr.repository.CropSourceOptions; + /** - * DTO used to store options for ImageMagick cropping. + * Deprecated crop options. * - * @author Nick Smith + * @deprecated replaced by {@link CropSourceOptions} + * @see CropSourceOptions */ -public class ImageCropOptions +public class ImageCropOptions extends CropSourceOptions { - private int height = -1; - private int width = -1; - private int xOffset = 0; - private int yOffset = 0; - private boolean isPercentageCrop = false; - private String gravity = null; - /** - * Gets the height of the cropped image. By default this is in pixels but if - * isPercentageCrop is set to true then it changes to - * percentage. - * - * @return the height - */ - public int getHeight() - { - return this.height; - } - - /** - * Sets the height of the cropped image. By default this is in pixels but if - * isPercentageCrop is set to true then it changes to - * percentage. - * - * @param height the height to set - */ - public void setHeight(int height) - { - this.height = height; - } - - /** - * Sets the width of the cropped image. By default this is in pixels but if - * isPercentageCrop is set to true then it changes to - * percentage. - * - * @return the width - */ - public int getWidth() - { - return this.width; - } - - /** - * Sets the width of the cropped image. By default this is in pixels but if - * isPercentageCrop is set to true then it changes to - * percentage. - * - * @param width the width to set - */ - public void setWidth(int width) - { - this.width = width; - } - - /** - * Gets the horizontal offset. By default this starts fromt he top-left - * corner of the image and moves right, however the gravity - * property can change this. - * - * @return the xOffset - */ - public int getXOffset() - { - return this.xOffset; - } - - /** - * Sets the horizontal offset. By default this starts fromt he top-left - * corner of the image and moves right, however the gravity - * property can change this. - * - * @param xOffset the xOffset to set - */ - public void setXOffset(int xOffset) - { - this.xOffset = xOffset; - } - - /** - * Gets the vertical offset. By default this starts fromt he top-left corner - * of the image and moves down, however the gravity property - * can change this. - * - * @return the yOffset - */ - public int getYOffset() - { - return this.yOffset; - } - - /** - * Sets the vertical offset. By default this starts fromt he top-left corner - * of the image and moves down, however the gravity property - * can change this. - * - * @param yOffset the yOffset to set - */ - public void setYOffset(int yOffset) - { - this.yOffset = yOffset; - } - - /** - * @return the isPercentageCrop - */ - public boolean isPercentageCrop() - { - return this.isPercentageCrop; - } - - /** - * @param isPercentageCrop the isPercentageCrop to set - */ - public void setPercentageCrop(boolean isPercentageCrop) - { - this.isPercentageCrop = isPercentageCrop; - } - - /** - * Sets the 'gravity' which determines how the offset is applied. It affects - * both the origin of offset and the direction(s). - * - * @param gravity the gravity to set - */ - public void setGravity(String gravity) - { - this.gravity = gravity; - } - - /** - * Gets the 'gravity' which determines how the offset is applied. It affects - * both the origin of offset and the direction(s). - * - * @return the gravity - */ - public String getGravity() - { - return this.gravity; - } - - @Override - public String toString() - { - StringBuilder builder = new StringBuilder(); - builder.append("ImageCropOptions [height=").append(this.height).append(", width=").append(this.width) - .append(", xOffset=").append(this.xOffset).append(", yOffset=").append(this.yOffset) - .append(", isPercentageCrop=").append(this.isPercentageCrop).append(", gravity=") - .append(this.gravity).append("]"); - return builder.toString(); - } } diff --git a/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java b/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java index 31ff8256ef..70013c9add 100644 --- a/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java +++ b/source/java/org/alfresco/repo/content/transform/magick/ImageMagickContentTransformerWorker.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -25,6 +25,7 @@ import java.util.Map; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.repo.content.MimetypeMap; import org.alfresco.service.cmr.repository.ContentIOException; +import org.alfresco.service.cmr.repository.CropSourceOptions; import org.alfresco.service.cmr.repository.PagedSourceOptions; import org.alfresco.service.cmr.repository.TransformationOptions; import org.alfresco.util.exec.RuntimeExec; @@ -154,7 +155,7 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont if (options instanceof ImageTransformationOptions) { ImageTransformationOptions imageOptions = (ImageTransformationOptions)options; - ImageCropOptions cropOptions = imageOptions.getCropOptions(); + CropSourceOptions cropOptions = imageOptions.getSourceOptions(CropSourceOptions.class); ImageResizeOptions resizeOptions = imageOptions.getResizeOptions(); String commandOptions = imageOptions.getCommandOptions(); if (commandOptions == null) @@ -199,7 +200,7 @@ public class ImageMagickContentTransformerWorker extends AbstractImageMagickCont * @param imageResizeOptions image resize options * @return String the imagemagick command options */ - private String getImageCropCommandOptions(ImageCropOptions cropOptions) + private String getImageCropCommandOptions(CropSourceOptions cropOptions) { StringBuilder builder = new StringBuilder(32); String gravity = cropOptions.getGravity(); diff --git a/source/java/org/alfresco/repo/content/transform/magick/ImageTransformationOptions.java b/source/java/org/alfresco/repo/content/transform/magick/ImageTransformationOptions.java index f9ebb42d57..94c0308522 100644 --- a/source/java/org/alfresco/repo/content/transform/magick/ImageTransformationOptions.java +++ b/source/java/org/alfresco/repo/content/transform/magick/ImageTransformationOptions.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.Map; import org.alfresco.service.cmr.repository.TransformationOptions; +import org.alfresco.service.cmr.repository.TransformationSourceOptions; /** * Image transformation options @@ -32,7 +33,6 @@ public class ImageTransformationOptions extends TransformationOptions { public static final String OPT_COMMAND_OPTIONS = "commandOptions"; public static final String OPT_IMAGE_RESIZE_OPTIONS = "imageResizeOptions"; - public static final String OPT_IMAGE_CROP_OPTIONS = "imageCropOptions"; public static final String OPT_IMAGE_AUTO_ORIENTATION = "imageAutoOrient"; /** Command string options, provided for backward compatibility */ @@ -41,9 +41,6 @@ public class ImageTransformationOptions extends TransformationOptions /** Image resize options */ private ImageResizeOptions resizeOptions; - /** Image crop options */ - private ImageCropOptions cropOptions; - private boolean autoOrient = true; /** * Set the command string options @@ -90,8 +87,22 @@ public class ImageTransformationOptions extends TransformationOptions { StringBuilder builder = new StringBuilder(); builder.append("ImageTransformationOptions [commandOptions=").append(this.commandOptions) - .append(", resizeOptions=").append(this.resizeOptions).append(", cropOptions=") - .append(this.cropOptions).append(", autoOrient=").append(this.autoOrient).append("]"); + .append(", resizeOptions=").append(this.resizeOptions) + .append(", autoOrient=").append(this.autoOrient).append("]"); + if (getSourceOptionsList() != null) + { + builder.append(", sourceOptions={ "); + int i = 0; + for (TransformationSourceOptions sourceOptions : getSourceOptionsList()) + { + builder.append((i != 0) ? " , ": ""); + builder.append(sourceOptions.getClass().getSimpleName()) + .append(sourceOptions.toString()); + i++; + } + builder.append("} "); + } + builder.append("]"); return builder.toString(); } @@ -105,28 +116,10 @@ public class ImageTransformationOptions extends TransformationOptions Map props = new HashMap(baseProps); props.put(OPT_COMMAND_OPTIONS, commandOptions); props.put(OPT_IMAGE_RESIZE_OPTIONS, resizeOptions); - props.put(OPT_IMAGE_CROP_OPTIONS, cropOptions); props.put(OPT_IMAGE_AUTO_ORIENTATION, autoOrient); return props; } - - /** - * @param cropOptions the cropOptions to set - */ - public void setCropOptions(ImageCropOptions cropOptions) - { - this.cropOptions = cropOptions; - } - - /** - * @return the cropOptions - */ - public ImageCropOptions getCropOptions() - { - return this.cropOptions; - } - /** * @return Will the image be automatically oriented(rotated) based on the EXIF "Orientation" data. * Defaults to TRUE @@ -154,7 +147,6 @@ public class ImageTransformationOptions extends TransformationOptions // Clone ImageTransformationOptions this.setCommandOptions(((ImageTransformationOptions) origOptions).getCommandOptions()); this.setResizeOptions(((ImageTransformationOptions) origOptions).getResizeOptions()); - this.setCropOptions(((ImageTransformationOptions) origOptions).getCropOptions()); this.setAutoOrient(((ImageTransformationOptions) origOptions).isAutoOrient()); } } diff --git a/source/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java b/source/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java index 155d426bfd..5523b97318 100644 --- a/source/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java +++ b/source/java/org/alfresco/repo/rendition/RenditionServiceIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -62,6 +62,7 @@ import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.service.cmr.repository.CropSourceOptions.CropSourceOptionsSerializer; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.ScriptLocation; @@ -652,8 +653,8 @@ public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest final int imageNewXSize = 36; final int imageNewYSize = 47; final Map parameterValues = new HashMap(); - parameterValues.put(ImageRenderingEngine.PARAM_CROP_WIDTH, imageNewXSize); - parameterValues.put(ImageRenderingEngine.PARAM_CROP_HEIGHT, imageNewYSize); + parameterValues.put(CropSourceOptionsSerializer.PARAM_CROP_WIDTH, imageNewXSize); + parameterValues.put(CropSourceOptionsSerializer.PARAM_CROP_HEIGHT, imageNewYSize); ImageTransformationOptions imageTransformationOptions = new ImageTransformationOptions(); final NodeRef newRenditionNode = performImageRendition(parameterValues,nodeWithImageContent); @@ -707,9 +708,9 @@ public class RenditionServiceIntegrationTest extends BaseAlfrescoSpringTest // Create a rendition of the same image, this time cropping by 50/25% parameterValues.clear(); - parameterValues.put(ImageRenderingEngine.PARAM_CROP_WIDTH, 50); // 256 picels - parameterValues.put(ImageRenderingEngine.PARAM_CROP_HEIGHT, 25); // 128 pixels - parameterValues.put(ImageRenderingEngine.PARAM_IS_PERCENT_CROP, true); + parameterValues.put(CropSourceOptionsSerializer.PARAM_CROP_WIDTH, 50); // 256 picels + parameterValues.put(CropSourceOptionsSerializer.PARAM_CROP_HEIGHT, 25); // 128 pixels + parameterValues.put(CropSourceOptionsSerializer.PARAM_IS_PERCENT_CROP, true); final NodeRef secondRenditionNode = performImageRendition(parameterValues,nodeWithImageContent); diff --git a/source/java/org/alfresco/repo/rendition/executer/ImageRenderingEngine.java b/source/java/org/alfresco/repo/rendition/executer/ImageRenderingEngine.java index c96a9c96a7..2b8ae24576 100644 --- a/source/java/org/alfresco/repo/rendition/executer/ImageRenderingEngine.java +++ b/source/java/org/alfresco/repo/rendition/executer/ImageRenderingEngine.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Alfresco Software Limited. + * Copyright (C) 2005-2013 Alfresco Software Limited. * * This file is part of Alfresco * @@ -22,13 +22,13 @@ package org.alfresco.repo.rendition.executer; import java.util.Collection; import org.alfresco.repo.action.ParameterDefinitionImpl; -import org.alfresco.repo.content.transform.magick.ImageCropOptions; import org.alfresco.repo.content.transform.magick.ImageResizeOptions; import org.alfresco.repo.content.transform.magick.ImageTransformationOptions; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ParameterDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.rendition.RenditionService; +import org.alfresco.service.cmr.repository.CropSourceOptions.CropSourceOptionsSerializer; import org.alfresco.service.cmr.repository.TransformationOptions; /** @@ -116,112 +116,6 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine */ public static final String PARAM_ALLOW_ENLARGEMENT = "allowEnlargement"; - // Crop params - /** - * This optional {@link Integer} or {@link Float} parameter specifies the - * width of the image after cropping. This may be expressed as pixels or it - * may represent a percentage of the original image width, depending on the - * value of the PARAM_IS_PERCENT_CROP parameter.
- * If no value is specified for this parameter then the width of the image - * will be unchanged.
- * If an image is being cropped and resized then the cropping happens first, - * followed by resizing of the cropped image. - */ - public static final String PARAM_CROP_WIDTH = "crop_width"; - - /** - * This optional {@link Integer} or {@link Float} parameter specifies the - * height of the image after cropping. This may be expressed as pixels or it - * may represent a percentage of the original image width, depending on the - * value of the PARAM_IS_PERCENT_CROP parameter.
- * If no value is specified for this parameter then the width of the image - * will be unchanged.
- * If an image is being cropped and resized then the cropping happens first, - * followed by resizing of the cropped image. - */ - public static final String PARAM_CROP_HEIGHT = "crop_height"; - - /** - * This optional {@link Integer} parameter specifies the horizontal position - * of the start point of the area to be cropped. By default this parameter - * sets the distance, in pixels, from the left-hand edge of the image to the - * start position of the crop area. By default a positive value will shift - * the start-position to the right, while a negative value will shift the - * start position to the left. Setting the PARAM_CROP_GRAVITY parameter may - * change this, however.
- * If this parameter is not set it is assumed to be 0. - */ - public static final String PARAM_CROP_X_OFFSET = "crop_x"; - - /** - * This optional {@link Integer} parameter specifies the vertical position - * of the start point of the area to be cropped. By default this parameter - * sets the distance, in pixels, from the top edge of the image to the start - * position of the crop area. By default a positive value will shift the - * start-position downwards, while a negative value will shift the start - * position upwards. Setting the PARAM_CROP_GRAVITY parameter may change - * this, however.
- * If this parameter is not set it is assumed to be 0. - */ - public static final String PARAM_CROP_Y_OFFSET = "crop_y"; - - /** - * This optional {@link String} parameter determines the 'zero' position - * from which offsets are measured and also determines the direction of - * offsets. The allowed values of gravity are the four cardinal points - * (North, East, etc.), the four ordinal points (NorhtWest, SouthEast, etc) - * and Center. By default NorthWest gravity is used. - *

- * - * If an ordinal gravity is set then the point from which offsets originate - * will be the appropriate corner. For example, NorthWest gravity would - * originate at teh top-left corner while SouthWest origin would originate - * at the bottom-left corner. Cardinal gravity sets the origin at the center - * of the appropriate edge. Center origin sets the origin at the center of - * the image. - *

- * - * Gravity also affects the direction of offsets and how the offset position - * relates to the cropped image. For example, NorthWest gravity sets - * positive horizontal offset direction to right, positive vertical - * direction to down and sets the cropped image origin to the top-left - * corner. Northerly gavities set the positive vertical direction to down. - * Southerly gavities set teh positive vertical direction to up. Easterly - * gavities set teh positive horizontal positive direction to left. Westerly - * gavities set teh positive horizontal positive direction to right. - *

- * Some gravity values do not specify a horizontal or a vertical direction - * explicitly. For example North does not specify a horizontal direction, - * while Center does not specify either horizontal or vertical direction. In - * thse cases the positive horizontal offset direction is always right and - * the positive vertical offset direction is always down. - *

- * - * The gravity also affects how the cropped image relates to the offset - * position. For example, NorthWest gravity causes the top-left corner of - * the cropped area to be the offset position, while NorthEast gravity would - * set the top-right corner of the cropped are to the offset position. When - * a direction is not explicitly specified then the center of the cropped - * area is placed at the offset position. For example, with North gravity - * the horizontal position is unspecified so the cropped area would be - * horizontally centered on the offset position, but the top edge of the - * cropped area would be at the offset position. For Center gravity the - * cropped area will be centered over the offset position both horizontally - * and vertically. - */ - public static final String PARAM_CROP_GRAVITY = "crop_gravity"; - - /** - * This optional {@link Boolean} flag parameter specifies how the - * PARAM_CROP_HEIGHT and PARAM_CROP_WIDTH parameters are interpreted. If - * this parameter is set to true then the cropped image height and - * width are represented as a percentage of the original image height and - * width. If this parameter is set to false then the rendition - * height and width are represented as pixels. This parameter defaults to - * false. - */ - public static final String PARAM_IS_PERCENT_CROP = "percent_crop"; - /** * This optional {@link String} parameter specifies any additional * ImageMagick commands, that the user wishes to add. These commands are @@ -261,12 +155,10 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine String commandOptions = context.getCheckedParam(PARAM_COMMAND_OPTIONS, String.class); ImageResizeOptions imageResizeOptions = getImageResizeOptions(context); - ImageCropOptions cropOptions = getImageCropOptions(context); boolean autoOrient = context.getParamWithDefault(PARAM_AUTO_ORIENTATION, true); imageTransformationOptions.setResizeOptions(imageResizeOptions); - imageTransformationOptions.setCropOptions(cropOptions); imageTransformationOptions.setAutoOrient(autoOrient); if (commandOptions != null) { @@ -309,31 +201,6 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine imageResizeOptions.setAllowEnlargement(allowEnlargement); return imageResizeOptions; } - - private ImageCropOptions getImageCropOptions(RenderingContext context) - { - int newWidth = context.getIntegerParam(PARAM_CROP_WIDTH, -1); - int newHeight = context.getIntegerParam(PARAM_CROP_HEIGHT, -1); - if (newHeight == -1 && newWidth == -1) - { - return null; - } - - int xOffset = context.getIntegerParam(PARAM_CROP_X_OFFSET, 0); - int yOffset = context.getIntegerParam(PARAM_CROP_Y_OFFSET, 0); - - boolean isPercentCrop = context.getParamWithDefault(PARAM_IS_PERCENT_CROP, false); - String gravity = context.getCheckedParam(PARAM_CROP_GRAVITY, String.class); - - ImageCropOptions cropOptions = new ImageCropOptions(); - cropOptions.setGravity(gravity); - cropOptions.setHeight(newHeight); - cropOptions.setPercentageCrop(isPercentCrop); - cropOptions.setWidth(newWidth); - cropOptions.setXOffset(xOffset); - cropOptions.setYOffset(yOffset); - return cropOptions; - } @Override protected void checkParameterValues(Action action) @@ -341,8 +208,8 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine // Some numerical parameters should not be zero or negative. checkNumericalParameterIsPositive(action, PARAM_RESIZE_WIDTH); checkNumericalParameterIsPositive(action, PARAM_RESIZE_HEIGHT); - checkNumericalParameterIsPositive(action, PARAM_CROP_HEIGHT); - checkNumericalParameterIsPositive(action, PARAM_CROP_WIDTH); + checkNumericalParameterIsPositive(action, CropSourceOptionsSerializer.PARAM_CROP_HEIGHT); + checkNumericalParameterIsPositive(action, CropSourceOptionsSerializer.PARAM_CROP_WIDTH); // Target mime type should only be an image MIME type String mimeTypeParam = (String)action.getParameterValue(PARAM_MIME_TYPE); @@ -404,18 +271,18 @@ public class ImageRenderingEngine extends AbstractTransformationRenderingEngine //Crop Params - paramList.add(new ParameterDefinitionImpl(PARAM_CROP_GRAVITY, DataTypeDefinition.TEXT, false, - getParamDisplayLabel(PARAM_CROP_GRAVITY))); - paramList.add(new ParameterDefinitionImpl(PARAM_CROP_HEIGHT, DataTypeDefinition.INT, false, - getParamDisplayLabel(PARAM_CROP_HEIGHT))); - paramList.add(new ParameterDefinitionImpl(PARAM_CROP_WIDTH, DataTypeDefinition.INT, false, - getParamDisplayLabel(PARAM_CROP_WIDTH))); - paramList.add(new ParameterDefinitionImpl(PARAM_CROP_X_OFFSET, DataTypeDefinition.INT, false, - getParamDisplayLabel(PARAM_CROP_X_OFFSET))); - paramList.add(new ParameterDefinitionImpl(PARAM_CROP_Y_OFFSET, DataTypeDefinition.INT, false, - getParamDisplayLabel(PARAM_CROP_Y_OFFSET))); - paramList.add(new ParameterDefinitionImpl(PARAM_IS_PERCENT_CROP, DataTypeDefinition.BOOLEAN, false, - getParamDisplayLabel(PARAM_IS_PERCENT_CROP))); + paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_GRAVITY, DataTypeDefinition.TEXT, false, + getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_GRAVITY))); + paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_HEIGHT, DataTypeDefinition.INT, false, + getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_HEIGHT))); + paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_WIDTH, DataTypeDefinition.INT, false, + getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_WIDTH))); + paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_X_OFFSET, DataTypeDefinition.INT, false, + getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_X_OFFSET))); + paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_CROP_Y_OFFSET, DataTypeDefinition.INT, false, + getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_CROP_Y_OFFSET))); + paramList.add(new ParameterDefinitionImpl(CropSourceOptionsSerializer.PARAM_IS_PERCENT_CROP, DataTypeDefinition.BOOLEAN, false, + getParamDisplayLabel(CropSourceOptionsSerializer.PARAM_IS_PERCENT_CROP))); paramList.add(new ParameterDefinitionImpl(PARAM_COMMAND_OPTIONS, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_COMMAND_OPTIONS))); diff --git a/source/java/org/alfresco/service/cmr/repository/AbstractTransformationSourceOptions.java b/source/java/org/alfresco/service/cmr/repository/AbstractTransformationSourceOptions.java index 7cd6d80bc4..b04c08817d 100644 --- a/source/java/org/alfresco/service/cmr/repository/AbstractTransformationSourceOptions.java +++ b/source/java/org/alfresco/service/cmr/repository/AbstractTransformationSourceOptions.java @@ -32,6 +32,7 @@ public abstract class AbstractTransformationSourceOptions implements Transformat { protected static final String MIMETYPE_VIDEO_PREFIX = "video/"; protected static final String MIMETYPE_AUDIO_PREFIX = "audio/"; + protected static final String MIMETYPE_IMAGE_PREFIX = "image/"; /** The list of applicable mimetypes */ private List applicabledMimetypes; diff --git a/source/java/org/alfresco/service/cmr/repository/CropSourceOptions.java b/source/java/org/alfresco/service/cmr/repository/CropSourceOptions.java new file mode 100644 index 0000000000..d53af47b46 --- /dev/null +++ b/source/java/org/alfresco/service/cmr/repository/CropSourceOptions.java @@ -0,0 +1,363 @@ +/* + * Copyright (C) 2005-2013 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + */ + +package org.alfresco.service.cmr.repository; + +import java.io.Serializable; +import java.util.Map; + +/** + * DTO used to store options for ImageMagick cropping. + * + * @author Nick Smith, Ray Gauss II + */ +public class CropSourceOptions extends AbstractTransformationSourceOptions +{ + private int height = -1; + private int width = -1; + private int xOffset = 0; + private int yOffset = 0; + private boolean isPercentageCrop = false; + private String gravity = null; + + @Override + public boolean isApplicableForMimetype(String sourceMimetype) + { + return ((sourceMimetype != null && + sourceMimetype.startsWith(MIMETYPE_IMAGE_PREFIX)) || + super.isApplicableForMimetype(sourceMimetype)); + } + + /** + * Gets the height of the cropped image. By default this is in pixels but if + * isPercentageCrop is set to true then it changes to + * percentage. + * + * @return the height + */ + public int getHeight() + { + return this.height; + } + + /** + * Sets the height of the cropped image. By default this is in pixels but if + * isPercentageCrop is set to true then it changes to + * percentage. + * + * @param height the height to set + */ + public void setHeight(int height) + { + this.height = height; + } + + /** + * Sets the width of the cropped image. By default this is in pixels but if + * isPercentageCrop is set to true then it changes to + * percentage. + * + * @return the width + */ + public int getWidth() + { + return this.width; + } + + /** + * Sets the width of the cropped image. By default this is in pixels but if + * isPercentageCrop is set to true then it changes to + * percentage. + * + * @param width the width to set + */ + public void setWidth(int width) + { + this.width = width; + } + + /** + * Gets the horizontal offset. By default this starts fromt he top-left + * corner of the image and moves right, however the gravity + * property can change this. + * + * @return the xOffset + */ + public int getXOffset() + { + return this.xOffset; + } + + /** + * Sets the horizontal offset. By default this starts fromt he top-left + * corner of the image and moves right, however the gravity + * property can change this. + * + * @param xOffset the xOffset to set + */ + public void setXOffset(int xOffset) + { + this.xOffset = xOffset; + } + + /** + * Gets the vertical offset. By default this starts fromt he top-left corner + * of the image and moves down, however the gravity property + * can change this. + * + * @return the yOffset + */ + public int getYOffset() + { + return this.yOffset; + } + + /** + * Sets the vertical offset. By default this starts fromt he top-left corner + * of the image and moves down, however the gravity property + * can change this. + * + * @param yOffset the yOffset to set + */ + public void setYOffset(int yOffset) + { + this.yOffset = yOffset; + } + + /** + * @return the isPercentageCrop + */ + public boolean isPercentageCrop() + { + return this.isPercentageCrop; + } + + /** + * @param isPercentageCrop the isPercentageCrop to set + */ + public void setPercentageCrop(boolean isPercentageCrop) + { + this.isPercentageCrop = isPercentageCrop; + } + + /** + * Sets the 'gravity' which determines how the offset is applied. It affects + * both the origin of offset and the direction(s). + * + * @param gravity the gravity to set + */ + public void setGravity(String gravity) + { + this.gravity = gravity; + } + + /** + * Gets the 'gravity' which determines how the offset is applied. It affects + * both the origin of offset and the direction(s). + * + * @return the gravity + */ + public String getGravity() + { + return this.gravity; + } + + @Override + public TransformationSourceOptionsSerializer getSerializer() + { + return CropSourceOptions.createSerializerInstance(); + } + + /** + * Creates an instance of the options serializer + * + * @return the options serializer + */ + public static TransformationSourceOptionsSerializer createSerializerInstance() + { + return (new CropSourceOptions()).new CropSourceOptionsSerializer(); + } + + @Override + public String toString() + { + StringBuilder builder = new StringBuilder(); + builder.append("CropSourceOptions [height=").append(this.height).append(", width=").append(this.width) + .append(", xOffset=").append(this.xOffset).append(", yOffset=").append(this.yOffset) + .append(", isPercentageCrop=").append(this.isPercentageCrop).append(", gravity=") + .append(this.gravity).append("]"); + return builder.toString(); + } + + /** + * Serializer for crop source options + */ + public class CropSourceOptionsSerializer implements TransformationSourceOptionsSerializer + { + + // Crop params + /** + * This optional {@link Integer} or {@link Float} parameter specifies the + * width of the image after cropping. This may be expressed as pixels or it + * may represent a percentage of the original image width, depending on the + * value of the PARAM_IS_PERCENT_CROP parameter.
+ * If no value is specified for this parameter then the width of the image + * will be unchanged.
+ * If an image is being cropped and resized then the cropping happens first, + * followed by resizing of the cropped image. + */ + public static final String PARAM_CROP_WIDTH = "crop_width"; + + /** + * This optional {@link Integer} or {@link Float} parameter specifies the + * height of the image after cropping. This may be expressed as pixels or it + * may represent a percentage of the original image width, depending on the + * value of the PARAM_IS_PERCENT_CROP parameter.
+ * If no value is specified for this parameter then the width of the image + * will be unchanged.
+ * If an image is being cropped and resized then the cropping happens first, + * followed by resizing of the cropped image. + */ + public static final String PARAM_CROP_HEIGHT = "crop_height"; + + /** + * This optional {@link Integer} parameter specifies the horizontal position + * of the start point of the area to be cropped. By default this parameter + * sets the distance, in pixels, from the left-hand edge of the image to the + * start position of the crop area. By default a positive value will shift + * the start-position to the right, while a negative value will shift the + * start position to the left. Setting the PARAM_CROP_GRAVITY parameter may + * change this, however.
+ * If this parameter is not set it is assumed to be 0. + */ + public static final String PARAM_CROP_X_OFFSET = "crop_x"; + + /** + * This optional {@link Integer} parameter specifies the vertical position + * of the start point of the area to be cropped. By default this parameter + * sets the distance, in pixels, from the top edge of the image to the start + * position of the crop area. By default a positive value will shift the + * start-position downwards, while a negative value will shift the start + * position upwards. Setting the PARAM_CROP_GRAVITY parameter may change + * this, however.
+ * If this parameter is not set it is assumed to be 0. + */ + public static final String PARAM_CROP_Y_OFFSET = "crop_y"; + + /** + * This optional {@link String} parameter determines the 'zero' position + * from which offsets are measured and also determines the direction of + * offsets. The allowed values of gravity are the four cardinal points + * (North, East, etc.), the four ordinal points (NorhtWest, SouthEast, etc) + * and Center. By default NorthWest gravity is used. + *

+ * + * If an ordinal gravity is set then the point from which offsets originate + * will be the appropriate corner. For example, NorthWest gravity would + * originate at teh top-left corner while SouthWest origin would originate + * at the bottom-left corner. Cardinal gravity sets the origin at the center + * of the appropriate edge. Center origin sets the origin at the center of + * the image. + *

+ * + * Gravity also affects the direction of offsets and how the offset position + * relates to the cropped image. For example, NorthWest gravity sets + * positive horizontal offset direction to right, positive vertical + * direction to down and sets the cropped image origin to the top-left + * corner. Northerly gavities set the positive vertical direction to down. + * Southerly gavities set teh positive vertical direction to up. Easterly + * gavities set teh positive horizontal positive direction to left. Westerly + * gavities set teh positive horizontal positive direction to right. + *

+ * Some gravity values do not specify a horizontal or a vertical direction + * explicitly. For example North does not specify a horizontal direction, + * while Center does not specify either horizontal or vertical direction. In + * thse cases the positive horizontal offset direction is always right and + * the positive vertical offset direction is always down. + *

+ * + * The gravity also affects how the cropped image relates to the offset + * position. For example, NorthWest gravity causes the top-left corner of + * the cropped area to be the offset position, while NorthEast gravity would + * set the top-right corner of the cropped are to the offset position. When + * a direction is not explicitly specified then the center of the cropped + * area is placed at the offset position. For example, with North gravity + * the horizontal position is unspecified so the cropped area would be + * horizontally centered on the offset position, but the top edge of the + * cropped area would be at the offset position. For Center gravity the + * cropped area will be centered over the offset position both horizontally + * and vertically. + */ + public static final String PARAM_CROP_GRAVITY = "crop_gravity"; + + /** + * This optional {@link Boolean} flag parameter specifies how the + * PARAM_CROP_HEIGHT and PARAM_CROP_WIDTH parameters are interpreted. If + * this parameter is set to true then the cropped image height and + * width are represented as a percentage of the original image height and + * width. If this parameter is set to false then the rendition + * height and width are represented as pixels. This parameter defaults to + * false. + */ + public static final String PARAM_IS_PERCENT_CROP = "percent_crop"; + + @Override + public TransformationSourceOptions deserialize(SerializedTransformationOptionsAccessor serializedOptions) + { + int newWidth = serializedOptions.getIntegerParam(PARAM_CROP_WIDTH, -1); + int newHeight = serializedOptions.getIntegerParam(PARAM_CROP_HEIGHT, -1); + if (newHeight == -1 && newWidth == -1) + { + return null; + } + + int xOffset = serializedOptions.getIntegerParam(PARAM_CROP_X_OFFSET, 0); + int yOffset = serializedOptions.getIntegerParam(PARAM_CROP_Y_OFFSET, 0); + + boolean isPercentCrop = serializedOptions.getParamWithDefault(PARAM_IS_PERCENT_CROP, false); + String gravity = serializedOptions.getCheckedParam(PARAM_CROP_GRAVITY, String.class); + + CropSourceOptions cropOptions = new CropSourceOptions(); + cropOptions.setGravity(gravity); + cropOptions.setHeight(newHeight); + cropOptions.setPercentageCrop(isPercentCrop); + cropOptions.setWidth(newWidth); + cropOptions.setXOffset(xOffset); + cropOptions.setYOffset(yOffset); + return cropOptions; + } + + @Override + public void serialize(TransformationSourceOptions sourceOptions, + Map parameters) + { + if (parameters == null || sourceOptions == null) + return; + CropSourceOptions cropSourceOptions = (CropSourceOptions) sourceOptions; + parameters.put(PARAM_CROP_WIDTH, cropSourceOptions.getWidth()); + parameters.put(PARAM_CROP_HEIGHT, cropSourceOptions.getHeight()); + parameters.put(PARAM_CROP_X_OFFSET, cropSourceOptions.getXOffset()); + parameters.put(PARAM_CROP_Y_OFFSET, cropSourceOptions.getYOffset()); + parameters.put(PARAM_CROP_GRAVITY, cropSourceOptions.getGravity()); + parameters.put(PARAM_IS_PERCENT_CROP, cropSourceOptions.isPercentageCrop()); + } + + } + +} diff --git a/source/java/org/alfresco/service/cmr/repository/TemporalSourceOptions.java b/source/java/org/alfresco/service/cmr/repository/TemporalSourceOptions.java index 2a419ae185..d54b574a56 100644 --- a/source/java/org/alfresco/service/cmr/repository/TemporalSourceOptions.java +++ b/source/java/org/alfresco/service/cmr/repository/TemporalSourceOptions.java @@ -44,6 +44,7 @@ public class TemporalSourceOptions extends AbstractTransformationSourceOptions /** The duration of the target video after the transformation */ private String duration; + @Override public boolean isApplicableForMimetype(String sourceMimetype) { return ((sourceMimetype != null && diff --git a/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java b/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java index 7d7de3691c..a42c29d131 100644 --- a/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java +++ b/source/java/org/alfresco/service/cmr/repository/TransformationOptions.java @@ -18,16 +18,12 @@ */ package org.alfresco.service.cmr.repository; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; -import java.util.List; import java.util.Map; import org.alfresco.service.cmr.repository.datatype.TypeConverter; import org.alfresco.service.namespace.QName; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Class containing values of options that are passed to content transformers. These options @@ -42,8 +38,6 @@ import org.apache.commons.logging.LogFactory; */ public class TransformationOptions implements Cloneable { - private static final Log logger = LogFactory.getLog(TransformationOptions.class); - /** Option map names to preserve backward compatibility */ public static final String OPT_SOURCE_NODEREF = "contentReaderNodeRef"; public static final String OPT_SOURCE_CONTENT_PROPERTY = "sourceContentProperty";