Package com.contentful.java.cda.image
Class ImageOption
- java.lang.Object
-
- com.contentful.java.cda.image.ImageOption
-
public class ImageOption extends java.lang.ObjectOptions for images to be used when an asset returns a url.- See Also:
CDAAsset.urlForImageWith(ImageOption...)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImageOption.FocusDefines the area of focus to crop to.static classImageOption.FormatDefines the possible formats of an image.static classImageOption.ResizeDefines the type of resizing possible.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Stringapply(java.lang.String url)Apply this image option to a url, replacing and updating this url.static ImageOptionbackgroundColorOf(int color)Define a background color.static ImageOptionbackgroundColorOf(int r, int g, int b)Define a background color by its components.static ImageOptionblackBackgroundColor()Define a background color as black.static ImageOptionfitOf(ImageOption.Resize resize)Change the behaviour of resizing.static ImageOptionfocusOn(ImageOption.Focus focus)Changes the focus area when using the fit type ofImageOption.Resize.thumb.static ImageOptionformatOf(ImageOption.Format format)Retrieve image of specific image format.java.lang.StringgetOperation()Return the operation of this optionstatic ImageOptionheightOf(int height)Set the height of the output image.static ImageOptionhttp()Prefix image urls with http.static ImageOptionhttps()Prefix image urls with secure http.static ImageOptionjpegQualityOf(int quality)Define the quality of the jpg image to be returned.static ImageOptionroundedCornerRadiusOf(float radius)Cut corners round.static ImageOptionwidthOf(int width)Define the width of the image to be represented.
-
-
-
Method Detail
-
formatOf
public static ImageOption formatOf(ImageOption.Format format)
Retrieve image of specific image format.- Parameters:
format- anImageOption.Formatto be used for returning the image.- Returns:
- an image option.
- See Also:
ImageOption.Format
-
jpegQualityOf
public static ImageOption jpegQualityOf(int quality)
Define the quality of the jpg image to be returned.- Parameters:
quality- an positive integer between 1 and 100.- Returns:
- an image option for updating the url.
- Throws:
java.lang.IllegalArgumentException- if quality is not between 1 and 100.
-
widthOf
public static ImageOption widthOf(int width)
Define the width of the image to be represented.- Parameters:
width- width in pixel of the image- Returns:
- an image option to be used for manipulating an image url.
- Throws:
java.lang.IllegalArgumentException- if width is not positive.
-
heightOf
public static ImageOption heightOf(int height)
Set the height of the output image.- Parameters:
height- size of image in pixel.- Returns:
- an ImageOption changing the height of an output image.
- Throws:
java.lang.IllegalArgumentException- if height is not positive.
-
fitOf
public static ImageOption fitOf(ImageOption.Resize resize)
Change the behaviour of resizing.By default the aspect ratio of the image is preserved when defining a size, or a width and height. Using this method, you can define a different resize behaviour.
- Parameters:
resize- the behaviour of resizing- Returns:
- an image option for manipulating a given url.
-
focusOn
public static ImageOption focusOn(ImageOption.Focus focus)
Changes the focus area when using the fit type ofImageOption.Resize.thumb.- Parameters:
focus- the area of focus.- Returns:
- an image option for manipulating a given url.
-
roundedCornerRadiusOf
public static ImageOption roundedCornerRadiusOf(float radius)
Cut corners round.- Parameters:
radius- of the inner circle in pixel- Returns:
- an image option for manipulating a given url.
- Throws:
java.lang.IllegalArgumentException- if the radius is negative.
-
backgroundColorOf
public static ImageOption backgroundColorOf(int color)
Define a background color.The color value must be a hexadecimal value, i.e. 0xFF0000 means red.
- Parameters:
color- the color in hex to be used.- Returns:
- an image option for manipulating a given url.
- Throws:
java.lang.IllegalArgumentException- if the color is less then zero or greater then 0xFFFFFF.
-
backgroundColorOf
public static ImageOption backgroundColorOf(int r, int g, int b)
Define a background color by its components.Each color component must be a hexadecimal in the range from 0 to 255 inclusively.
- Parameters:
r- the red color component in hex to be used.g- the green color component in hex to be used.b- the blue color component in hex to be used.- Returns:
- an image option for manipulating a given url.
- Throws:
java.lang.IllegalArgumentException- if a component is less then zero or greater then 255.
-
blackBackgroundColor
public static ImageOption blackBackgroundColor()
Define a background color as black.- Returns:
- an image option for manipulating a given url.
-
http
public static ImageOption http()
Prefix image urls with http.If a protocol (either http or https) was already specified, this one will be taken and this option will not have any effect.
- Returns:
- an image option changing a given url to use insecure http transport.
-
https
public static ImageOption https()
Prefix image urls with secure http.If a protocol (either http or https) was already specified, this one will be taken and this option will not have any effect.
- Returns:
- an image option changing a given url to use secure http transport.
- Throws:
java.lang.IllegalArgumentException- ifhttp()or this method was called before.
-
apply
public java.lang.String apply(java.lang.String url)
Apply this image option to a url, replacing and updating this url.- Parameters:
url- a url to be handled- Returns:
- the changed url.
-
getOperation
public java.lang.String getOperation()
Return the operation of this option- Returns:
- a string representing this option.
-
-