com.squareup.pollexor
Class Pollexor

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

public final class Pollexor
extends Object

Fluent interface to create a URL appropriate for passing to Thumbor.

See Also:
image(java.lang.String)

Nested Class Summary
static class Pollexor.HorizontalAlign
          Horizontal alignment for crop positioning.
static class Pollexor.UnableToBuildException
          Exception denoting that a fatal error occurred while assembling the URL for the current configuration.
static class Pollexor.VerticalAlign
          Vertical alignment for crop positioning.
 
Method Summary
 Pollexor align(Pollexor.HorizontalAlign align)
          Set the horizontal alignment for the image when cropping.
 Pollexor align(Pollexor.VerticalAlign align)
          Set the vertical alignment for the image when cropping.
 Pollexor align(Pollexor.VerticalAlign valign, Pollexor.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.
 Pollexor crop(int top, int left, int bottom, int right)
          Crop the image between two points.
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.
 Pollexor filter(String... filters)
          Add one or more filters to the image.
 Pollexor fitIn()
          Contrain the image size inside the resized box, scaling as needed.
 Pollexor flipHorizontally()
          Flip the image horizontally.
 Pollexor flipVertically()
          Flip the image vertically.
static String frame(String imageUrl)
          This filter uses a 9-patch to overlay the image.
 Pollexor host(String host)
          Set a host to prepend to URL for a full URL output.
static Pollexor image(String target)
          Start building an image URL for Thumbor.
 Pollexor key(String key)
          Set a key for secure URL generation.
 Pollexor 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).
 Pollexor 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.
 Pollexor 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.
static String watermark(Pollexor image)
          This filter adds a watermark to the image at (0, 0).
static String watermark(Pollexor image, int x, int y)
          This filter adds a watermark to the image.
static String watermark(Pollexor image, int x, int y, int transparency)
          This filter adds a watermark to the 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

image

public static Pollexor image(String target)
Start building an image URL for Thumbor.

Parameters:
target - Target image to manipulate.
Throws:
Pollexor.UnableToBuildException - if target is blank.

key

public Pollexor key(String key)
Set a key for secure URL generation. This will default the toUrl() and toMeta() to build safe URLs.

Parameters:
key - Security key for remote server.
Throws:
Pollexor.UnableToBuildException - if key is blank.

host

public Pollexor host(String host)
Set a host to prepend to URL for a full URL output.

Parameters:
host - Host name.
Throws:
Pollexor.UnableToBuildException - if host is blank.

resize

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

Parameters:
width - Desired width.
height - Desired height.
Throws:
Pollexor.UnableToBuildException - if width or height is less than 1.

flipHorizontally

public Pollexor flipHorizontally()
Flip the image horizontally.

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

flipVertically

public Pollexor flipVertically()
Flip the image vertically.

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

fitIn

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

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

crop

public Pollexor 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:
Pollexor.UnableToBuildException - 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 Pollexor align(Pollexor.HorizontalAlign align)
Set the horizontal alignment for the image when cropping.

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

align

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

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

align

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

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

smart

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

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

legacy

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


filter

public Pollexor 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:
Pollexor.UnableToBuildException - 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(Pollexor), watermark(String, int, int), watermark(Pollexor, int, int), watermark(String, int, int, int), watermark(Pollexor, int, int, int)

toUrl

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

Throws:
Pollexor.UnableToBuildException

toUrlUnsafe

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


toUrlSafe

public String toUrlSafe()
Build a safe version of the URL. Requires a prior call to key(String).

Throws:
Pollexor.UnableToBuildException

toMeta

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

Throws:
Pollexor.UnableToBuildException

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 prior call to key(String).

Throws:
Pollexor.UnableToBuildException

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:
Pollexor.UnableToBuildException - 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:
Pollexor.UnableToBuildException - 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:
Pollexor.UnableToBuildException - 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:
Pollexor.UnableToBuildException - 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:
Pollexor.UnableToBuildException - 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:
Pollexor.UnableToBuildException - if image is blank.

watermark

public static String watermark(Pollexor 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:
Pollexor.UnableToBuildException - 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:
Pollexor.UnableToBuildException - if image is blank.

watermark

public static String watermark(Pollexor 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:
Pollexor.UnableToBuildException - 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:
Pollexor.UnableToBuildException - if image is blank or transparency is outside bounds.

watermark

public static String watermark(Pollexor 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:
Pollexor.UnableToBuildException - 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.

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.



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