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- * - * 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
+ *
+ * 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 ListisPercentageCrop
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.
+ * 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