com.squareup.pollexor
Class ThumborUrlBuilder

java.lang.Object
  extended by com.squareup.pollexor.ThumborUrlBuilder

public final class ThumborUrlBuilder
extends Object

Fluent interface to build a Thumbor URL.

See Also:
Thumbor.buildImage(String)

Nested Class Summary
static class ThumborUrlBuilder.HorizontalAlign
          Horizontal alignment for crop positioning.
static class ThumborUrlBuilder.ImageFormat
          Image formats supported by Thumbor.
static class ThumborUrlBuilder.TrimPixelColor
          Orientation from where to get the pixel color for trim.
static class ThumborUrlBuilder.VerticalAlign
          Vertical alignment for crop positioning.
 
Field Summary
static int ORIGINAL_SIZE
          Original size for image width or height.
 
Method Summary
 ThumborUrlBuilder align(ThumborUrlBuilder.HorizontalAlign align)
          Set the horizontal alignment for the image when cropping.
 ThumborUrlBuilder align(ThumborUrlBuilder.VerticalAlign align)
          Set the vertical alignment for the image when cropping.
 ThumborUrlBuilder align(ThumborUrlBuilder.VerticalAlign valign, ThumborUrlBuilder.HorizontalAlign halign)
          Set the horizontal and vertical alignment for the image when cropping.
static String brightness(int amount)
          This filter increases or decreases the image brightness.
static String contrast(int amount)
          The filter increases or decreases the image contrast.
 ThumborUrlBuilder crop(int top, int left, int bottom, int right)
          Crop the image between two points.
static String equalize()
          This filter equalizes the color distribution in the image.
static String fill(int color)
          This filter permit to return an image sized exactly as requested wherever is its ratio by filling with chosen color the missing parts.
 ThumborUrlBuilder filter(String... filters)
          Add one or more filters to the image.
 ThumborUrlBuilder fitIn()
          Contrain the image size inside the resized box, scaling as needed.
 ThumborUrlBuilder flipHorizontally()
          Flip the image horizontally.
 ThumborUrlBuilder flipVertically()
          Flip the image vertically.
static String format(ThumborUrlBuilder.ImageFormat format)
          Specify the output format of the image.
static String frame(String imageUrl)
          This filter uses a 9-patch to overlay the image.
static String grayscale()
          This filter changes the image to grayscale.
 ThumborUrlBuilder legacy()
          Use legacy encryption when constructing a safe URL.
static String noise(int amount)
          This filter adds noise to the image.
static String quality(int amount)
          This filter changes the overall quality of the JPEG image (does nothing for PNGs or GIFs).
 ThumborUrlBuilder resize(int width, int height)
          Resize picture to desired size.
static String rgb(int r, int g, int b)
          This filter changes the amount of color in each of the three channels.
static String roundCorner(int radius)
          This filter adds rounded corners to the image using the white as the background.
static String roundCorner(int radius, int color)
          This filter adds rounded corners to the image using the specified color as the background.
static String roundCorner(int radiusInner, int radiusOuter, int color)
          This filter adds rounded corners to the image using the specified color as the background.
static String sharpen(float amount, float radius, boolean luminanceOnly)
          This filter enhances apparent sharpness of the image.
 ThumborUrlBuilder smart()
          Use smart cropping for determining the important portion of an image.
static String stripicc()
          This filter strips the ICC profile from the image.
 String toMeta()
          Build the metadata URL.
 String toMetaSafe()
          Build a safe version of the metadata URL.
 String toMetaUnsafe()
          Build an unsafe version of the metadata URL.
 String toString()
           
 String toUrl()
          Build the URL.
 String toUrlSafe()
          Build a safe version of the URL.
 String toUrlUnsafe()
          Build an unsafe version of the URL.
 ThumborUrlBuilder trim()
          Removing surrounding space in image.
 ThumborUrlBuilder trim(ThumborUrlBuilder.TrimPixelColor value)
          Removing surrounding space in image.
 ThumborUrlBuilder trim(ThumborUrlBuilder.TrimPixelColor value, int colorTolerance)
          Removing surrounding space in image.
static String watermark(String imageUrl)
          This filter adds a watermark to the image at (0, 0).
static String watermark(String imageUrl, int x, int y)
          This filter adds a watermark to the image.
static String watermark(String imageUrl, int x, int y, int transparency)
          This filter adds a watermark to the image.
static String watermark(ThumborUrlBuilder image)
          This filter adds a watermark to the image at (0, 0).
static String watermark(ThumborUrlBuilder image, int x, int y)
          This filter adds a watermark to the image.
static String watermark(ThumborUrlBuilder image, int x, int y, int transparency)
          This filter adds a watermark to the image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ORIGINAL_SIZE

public static final int ORIGINAL_SIZE
Original size for image width or height.

See Also:
Constant Field Values
Method Detail

resize

public ThumborUrlBuilder resize(int width,
                                int height)
Resize picture to desired size.

Parameters:
width - Desired width.
height - Desired height.
Throws:
IllegalArgumentException - if width or height is less than 0 or both are 0.

flipHorizontally

public ThumborUrlBuilder flipHorizontally()
Flip the image horizontally.

Throws:
IllegalStateException - if image has not been marked for resize.

flipVertically

public ThumborUrlBuilder flipVertically()
Flip the image vertically.

Throws:
IllegalStateException - if image has not been marked for resize.

fitIn

public ThumborUrlBuilder fitIn()
Contrain the image size inside the resized box, scaling as needed.

Throws:
IllegalStateException - if image has not been marked for resize.

crop

public ThumborUrlBuilder crop(int top,
                              int left,
                              int bottom,
                              int right)
Crop the image between two points.

Parameters:
top - Top bound.
left - Left bound.
bottom - Bottom bound.
right - Right bound.
Throws:
IllegalArgumentException - if top or left are less than zero or bottom or right are less than one or less than top or left, respectively.

align

public ThumborUrlBuilder align(ThumborUrlBuilder.HorizontalAlign align)
Set the horizontal alignment for the image when cropping.

Parameters:
align - Horizontal alignment.
Throws:
IllegalStateException - if image has not been marked for crop.

align

public ThumborUrlBuilder align(ThumborUrlBuilder.VerticalAlign align)
Set the vertical alignment for the image when cropping.

Parameters:
align - Vertical alignment.
Throws:
IllegalStateException - if image has not been marked for crop.

align

public ThumborUrlBuilder align(ThumborUrlBuilder.VerticalAlign valign,
                               ThumborUrlBuilder.HorizontalAlign halign)
Set the horizontal and vertical alignment for the image when cropping.

Parameters:
valign - Vertical alignment.
halign - Horizontal alignment.
Throws:
IllegalStateException - if image has not been marked for crop.

smart

public ThumborUrlBuilder smart()
Use smart cropping for determining the important portion of an image.

Throws:
IllegalStateException - if image has not been marked for crop.

trim

public ThumborUrlBuilder trim()
Removing surrounding space in image.


trim

public ThumborUrlBuilder trim(ThumborUrlBuilder.TrimPixelColor value)
Removing surrounding space in image. Get trim color from specified pixel.

Parameters:
value - orientation from where to get the pixel color.

trim

public ThumborUrlBuilder trim(ThumborUrlBuilder.TrimPixelColor value,
                              int colorTolerance)
Removing surrounding space in image. Get trim color from specified pixel.

Parameters:
value - orientation from where to get the pixel color.
colorTolerance - 0 - 442. This is the euclidian distance between the colors of the reference pixel and the surrounding pixels is used. If the distance is within the tolerance they'll get trimmed.

legacy

public ThumborUrlBuilder legacy()
Use legacy encryption when constructing a safe URL.


filter

public ThumborUrlBuilder filter(String... filters)
Add one or more filters to the image.

If you have custom filters you can supply them as a string. (e.g. "my_filter(1,2,3)").

Parameters:
filters - Filter strings.
Throws:
IllegalArgumentException - if no arguments supplied or an argument is null.
See Also:
brightness(int), contrast(int), fill(int), frame(String), noise(int), quality(int), rgb(int, int, int), roundCorner(int), roundCorner(int, int), roundCorner(int, int, int), sharpen(float, float, boolean), watermark(String), watermark(ThumborUrlBuilder), watermark(String, int, int), watermark(ThumborUrlBuilder, int, int), watermark(String, int, int, int), watermark(ThumborUrlBuilder, int, int, int)

toUrl

public String toUrl()
Build the URL. This will either call toUrlSafe() or toUrlUnsafe() depending on whether a key was set.


toUrlUnsafe

public String toUrlUnsafe()
Build an unsafe version of the URL.


toUrlSafe

public String toUrlSafe()
Build a safe version of the URL. Requires a non-null key.


toMeta

public String toMeta()
Build the metadata URL. This will either call toMetaSafe() or toMetaUnsafe() depending on whether a key was set.


toMetaUnsafe

public String toMetaUnsafe()
Build an unsafe version of the metadata URL.


toMetaSafe

public String toMetaSafe()
Build a safe version of the metadata URL. Requires a non-null key.


toString

public String toString()
Overrides:
toString in class Object

brightness

public static String brightness(int amount)
This filter increases or decreases the image brightness.

Parameters:
amount - -100 to 100 - The amount (in %) to change the image brightness. Positive numbers make the image brighter and negative numbers make the image darker.
Throws:
IllegalArgumentException - if amount outside bounds.

contrast

public static String contrast(int amount)
The filter increases or decreases the image contrast.

Parameters:
amount - -100 to 100 - The amount (in %) to change the image contrast. Positive numbers increase contrast and negative numbers decrease contrast.
Throws:
IllegalArgumentException - if amount outside bounds.

noise

public static String noise(int amount)
This filter adds noise to the image.

Parameters:
amount - 0 to 100 - The amount (in %) of noise to add to the image.
Throws:
IllegalArgumentException - if amount outside bounds.

quality

public static String quality(int amount)
This filter changes the overall quality of the JPEG image (does nothing for PNGs or GIFs).

Parameters:
amount - 0 to 100 - The quality level (in %) that the end image will feature.
Throws:
IllegalArgumentException - if amount outside bounds.

rgb

public static String rgb(int r,
                         int g,
                         int b)
This filter changes the amount of color in each of the three channels.

Parameters:
r - The amount of redness in the picture. Can range from -100 to 100 in percentage.
g - The amount of greenness in the picture. Can range from -100 to 100 in percentage.
b - The amount of blueness in the picture. Can range from -100 to 100 in percentage.
Throws:
IllegalArgumentException - if r, g, or b are outside of bounds.

roundCorner

public static String roundCorner(int radius)
This filter adds rounded corners to the image using the white as the background.

Parameters:
radius - amount of pixels to use as radius.

roundCorner

public static String roundCorner(int radius,
                                 int color)
This filter adds rounded corners to the image using the specified color as the background.

Parameters:
radius - amount of pixels to use as radius.
color - fill color for clipped region.

roundCorner

public static String roundCorner(int radiusInner,
                                 int radiusOuter,
                                 int color)
This filter adds rounded corners to the image using the specified color as the background.

Parameters:
radiusInner - amount of pixels to use as radius.
radiusOuter - specifies the second value for the ellipse used for the radius. Use 0 for no value.
color - fill color for clipped region.

watermark

public static String watermark(String imageUrl)
This filter adds a watermark to the image at (0, 0).

Parameters:
imageUrl - Watermark image URL. It is very important to understand that the same image loader that Thumbor uses will be used here.
Throws:
IllegalArgumentException - if image is blank.

watermark

public static String watermark(ThumborUrlBuilder image)
This filter adds a watermark to the image at (0, 0).

Parameters:
image - Watermark image URL. It is very important to understand that the same image loader that Thumbor uses will be used here.
Throws:
IllegalArgumentException - if image is null.

watermark

public static String watermark(String imageUrl,
                               int x,
                               int y)
This filter adds a watermark to the image.

Parameters:
imageUrl - Watermark image URL. It is very important to understand that the same image loader that Thumbor uses will be used here.
x - Horizontal position that the watermark will be in. Positive numbers indicate position from the left and negative numbers indicate position from the right.
y - Vertical position that the watermark will be in. Positive numbers indicate position from the top and negative numbers indicate position from the bottom.
Throws:
IllegalArgumentException - if image is blank.

watermark

public static String watermark(ThumborUrlBuilder image,
                               int x,
                               int y)
This filter adds a watermark to the image.

Parameters:
image - Watermark image URL. It is very important to understand that the same image loader that Thumbor uses will be used here.
x - Horizontal position that the watermark will be in. Positive numbers indicate position from the left and negative numbers indicate position from the right.
y - Vertical position that the watermark will be in. Positive numbers indicate position from the top and negative numbers indicate position from the bottom.
Throws:
IllegalArgumentException - if image is null.

watermark

public static String watermark(String imageUrl,
                               int x,
                               int y,
                               int transparency)
This filter adds a watermark to the image.

Parameters:
imageUrl - Watermark image URL. It is very important to understand that the same image loader that Thumbor uses will be used here.
x - Horizontal position that the watermark will be in. Positive numbers indicate position from the left and negative numbers indicate position from the right.
y - Vertical position that the watermark will be in. Positive numbers indicate position from the top and negative numbers indicate position from the bottom.
transparency - Watermark image transparency. Should be a number between 0 (fully opaque) and 100 (fully transparent).
Throws:
IllegalArgumentException - if image is blank or transparency is outside bounds.

watermark

public static String watermark(ThumborUrlBuilder image,
                               int x,
                               int y,
                               int transparency)
This filter adds a watermark to the image.

Parameters:
image - Watermark image URL. It is very important to understand that the same image loader that Thumbor uses will be used here.
x - Horizontal position that the watermark will be in. Positive numbers indicate position from the left and negative numbers indicate position from the right.
y - Vertical position that the watermark will be in. Positive numbers indicate position from the top and negative numbers indicate position from the bottom.
transparency - Watermark image transparency. Should be a number between 0 (fully opaque) and 100 (fully transparent).
Throws:
IllegalArgumentException - if image is null.

sharpen

public static String sharpen(float amount,
                             float radius,
                             boolean luminanceOnly)
This filter enhances apparent sharpness of the image. It's heavily based on Marco Rossini's excellent Wavelet sharpen GIMP plugin. Check http://registry.gimp.org/node/9836 for details about how it work.

Parameters:
amount - Sharpen amount. Typical values are between 0.0 and 10.0.
radius - Sharpen radius. Typical values are between 0.0 and 2.0.
luminanceOnly - Sharpen only luminance channel.

fill

public static String fill(int color)
This filter permit to return an image sized exactly as requested wherever is its ratio by filling with chosen color the missing parts. Usually used with "fit-in" or "adaptive-fit-in"

Parameters:
color - integer representation of color.

format

public static String format(ThumborUrlBuilder.ImageFormat format)
Specify the output format of the image.

See Also:
ThumborUrlBuilder.ImageFormat

frame

public static String frame(String imageUrl)
This filter uses a 9-patch to overlay the image.

Parameters:
imageUrl - Watermark image URL. It is very important to understand that the same image loader that Thumbor uses will be used here.

stripicc

public static String stripicc()
This filter strips the ICC profile from the image.


grayscale

public static String grayscale()
This filter changes the image to grayscale.


equalize

public static String equalize()
This filter equalizes the color distribution in the image.



Copyright © 2012-2014 Square, Inc.. All Rights Reserved.