For easy integration with your projects, we supply two libraries for Ruby/Rails:
phocoder-rb -
A simple API wrapper for general Ruby applications.
phocoder-rails -
A rails plugin that makes it easy to add image handling to ActiveRecord models.
API Endpoint URL
All API Requests should be directed to the main API URL : http://www.phocoder.com/
API Request/Response Formats
API requests can be submitted in one of two formats. JSON and XML. The format of the response will be dependent on the format of the request.
Please note: At this time the JSON format API is well tested and is being used in production on a number of sites.
The XML API may still be a bit rough around the edges, but we are looking for testers. If you are interested in using the XML
API please let us know so that we can work with you if needed to make sure that things go as smoothly as possible.
Common API Request Parameters
For all API requests, you must include an api_key parameter.
JSON
{
api_key : "XXXXXXXXX"
}
XML
XXXXXXXXXXX
Creating Jobs
All jobs share the same basic creating process.
Assemble your job parameters in either JSON or XML format.
POST your job parameters to http://www.phocoder.com/jobs
Use the job response to create/update records for the outputs that are to be created.
Listen for notifications in order to know when your output is ready.
Common Job Creation Request Parameters
For all job creation requests, you must include a type parameter
and you may optionaly include a queue_name parameter.
type : One of ThumbnailJob,HdrJob,
TonemappingJob, or ComositeJob.
queue_name :
An options parameter that allows you to specify a queue name for this job.
This can be used to ensure fair queueing of jobs. If you're building a user
facing app, you may want to use the user id as the queue_name param to ensure
fair scheduling of jobs across all of your simultaneous users.
A thumbnail job will take one image file as an input and produce one or more 'thumbnail' versions of the image.
'Thumbnail' is a loose term since the images produced may be several mega pixels in size depending on your job settings.
Thumbnail Job Parameters
input : The URL of the input image.
Inputs may be any type of image including most RAW formats from digital cameras.
If you submit an image that give you problems, please let us know about it.
thumbnails : An array of one or more thumbnail parameter groups. Thumbnail parameter are:
format : Either 'jpg' or 'png'. Defaults to 'jpg' if not specified.
filename : The filename for the thumbnail. If not specified a filename will be randomly generated.
width : The width of the thumbnail to produce. If width is not specified the amount of scaling will depend entirely on the height parameter. Either width or height must be specified.
height : The height of the thumbnail to produce. If height is not specified the amount of scaling will depend entirely on the width parameter. Either width or height must be specified.
aspect_mode : 'preserver', 'stretch', 'crop', or 'pad'
label : An optional label to help you identify this thumbnail.
frame : An optional list of parameters describing a frame to add around the thumbnail.
width : The width of the frame. This will be applied 'inside' the dimensions specified for the thumbnail and the actual image will be scaled down accordingly.
color : A hex value representing the color of your frame.
notifications : An array of one or more notification parameters. Notification parameters are:
url : The URL where the notification data should be POSTed.
format : Either 'json' or 'xml'. Defaults to 'json'.
annotations : An arrary of one or more annotaion parameter groups. Annotation parameters are:
text : The string of text that should be laid over the image.
pointize : The size in pixels of the text.
fill_color : A hex value representing the inner fill color of the text.
stroke_color : A hex value representing the outter stroke color of the text.
stroke_width : The width of the stroke of the text.
stroke_inner : A boolean (true or false). Whether or not the stroke is applied to the inner potion of the text or only the outter.
rotation : The number of degrees of rotatio to apply to the text. 0 - 360
opacity : A float value representing percentage opacity of the text. 0 - 100
gravity : The general orientation of the text within the image.
x and y parameters are used to 'nudge' the text in a direction relative to the gravity setting.
Gravity options are: North, South, East, West, NorthEast, NorthWest, SouthEast, SouthWest, or Center.
x : A pixel value to 'nudge' the text in the horizontal direction relative to the gravity setting.
y : A pixel value to 'nudge' the text in the vertical direction relative to the gravity setting.
If you wanted to produce a 'medium' version of an image that would fit inside of a 400x400 square, while maintaining the original aspect ratio,
and also produce a 'small' 100x100 cropped thumbnail you would use a request something like this.
Once a thumbnail job has been accepted for processing Phocoder will return an immediate response with
details about each thumbnail that will be produced as part of that job.
id : The Phocoder system id for this job. This id may be used to look up job status.
inputs : An array containing a single parameter hash of data about the input for the job.
This returns a single member array instead of a single hash to match the format of the response for HDR jobs, which may have more than one input.
Input attributes are :
id : The Phocoder system id for this input.
thumbnails : An array of thumbnail attributes.
id : The Phocoder system id for this thumbnail. This id can be used to look up the status of this thumbnail.
label : The label supplied when the job was created.
filename : The filename of the thumbnail that will be created.
An HDR job will take one or more images as inputs and merge them to a single HDR file.
The inputs can optionaly be auto-aligned if they were not captured on a tripod.
HDR Job Parameters
Most of these parameters are passed to pfshdrcalibrate. Explanation of the parameters from from the pfstools documentation.
inputs : An array of input images to be merged to HDR.
hdr : A set of parameters representing the output HDR file.
HDR parameters are:
response : Allows to choose from predefined response curves. This can be used either to apply this response or use it as an initialization for automatic self-calibration. Predefined response curves are: "linear", "gamma", "log". Default is "linear". This option can be used only with Robertson method.
calibration : Type of automatic self-calibration method used for recovery of the response curve and/or type of method used for HDR merging. Accepted types include: "robertson", "mitsunaga". "robertson" is the default and recommended algorithm.
gauss : Sigma value for the Gaussian used as a weighting function. Applies to Robertson02 algorithm. Default value: 0.2. Range is 0-1.
multiplier : Input multiplier value. Can be used to manipulate the range of source exposures. Default value is 256 since LDR images are by default scaled to 0..1.
bpp : Number of bits per pixel in input data from the camera. Default value is 8.
samples : Number of sample pixels used in inverse response computations in Mitsunaga algorithm. Default is 50000.
fix_saturated : Use this option if you see black pixels in overexposed / satu‐
rated areas. The black pixels are visible if all exposures con‐
tain pixel values that are outside reliable range (are under- or
over-exposed). This flag gives non-zero weight for the brightest
and the darkest pixels, thus avoiding zero-weighted pixels. Note
that the calculated luminance values for these pixels are not
reliable.
luminance : Recovery of response curve will be performed for luminance channel only.
scale : A boolean value indicating whether or not to scale the resulting HDR file.
scale_width : The max width for the resulting HDR file. Must pass 'true' to the 'scale' parameter for this to take effect.
scale_height : The max height for the resulting HDR file. Must pass 'true' to the 'scale' parameter for this to take effect.
align : A boolean value indicating whether or not to perform auto-alignement of the input exposures before merging to HDR.
optimize_gauss : A boolean value indicating whether to optimize the gauss value. See the "optimize gauss" discussion below.
starting_gauss : The starting value for gauss to use when optimizing.
base_url : The base URL where the resulting HDR file should be stored. If not specified the file will be stored in our S3 bucket for 24 hours or more and you will need to download it and place it where you need it.
filename : The filename for the resulting HDR. If not specified, one will be randomly generated.
label : An optional label that you can use to track this job.
Optimize Gauss
The gauss setting is the primary way to control the number of saturated pixels in the output HDR.
In order to optimize your HDR file around the gauss setting it is recommended that you pass in a 'starting_gauss' of 0.5
and 'true' for 'optimize_gauss'. Then we'll generate an HDR file with gauss 0.5 and examine the number of saturated pixels in the output.
If the number of saturated pixels is greater than 1% we will try a slightly lower gauss and repeat the process. Once the number of saturated
pixels in the output is less than 1% we will consider the HDR file to be optimized. Passing in a value lower than 0.5 for 'starting_gauss' may
speed up the optimization process, particularly if there are a small number of input images, or if they are all especially dark or light.
If you have two images that you want to auto-align and merge to one 'gauss optimized' HDR image called 'my-image.hdr' you would use a request like this:
Once an hdr job has been accepted for processing Phocoder will return an immediate response with
details about the output file that will be produced as part of that job.
id : The Phocoder system id for this job. This id may be used to look up job status.
inputs : An array containing parameter hashes of data about each of the inputs for the job.
Input attributes are :
id : The Phocoder system id for this input.
hdr : A set of HDR attributes.
id : The Phocoder system id for this hdr. This id can be used to look up the status of this hdr.
label : The label supplied when the job was created.
filename : The filename of the hdr that will be created.
A sample thumbnail job resonse:
JSON
{
job : {
id : 1234,
inputs : [{ id : 1234 },{ id : 1235 }],
hdr : {
id : 1234,
label : "hdr",
filename : "my-image.hdr"
}
}
}
Creating a Tonemapping Job
A tonemapping job will take one image file as an input and produce a tonemapped version of it based on the parameters passed in.
Optionally one or more thumbnails may be created as a part of the job.
Many of the options for tonemapping jobs come from the operators in the pfstools collection. The descrtion of those parameters
comes from the pfstools documentation.
Tonemapping Job Parameters
input : The URL of the input image.
The recommended input format for tonemapping jobs is an HDR file.
Inputs may also be any type of image including most RAW formats from digital cameras.
If you submit an image that give you problems, please let us know about it.
tone_mapping : A set of tonemapping parameters. Available parameters are:
operator : Indicate which tonemapping operator to use. Options are "mantiuk06", "fattal02", "reinhard02", "reinhard05", "drago03", "durand02" and "pattanaik00". Default is "mantiuk06". ("mantiuk08" is planned for the future.)
factor : Applies to "mantiuk06" operator.
Contrast scaling factor (values 0-1) determines how much con‐
trast magnitudes should be reduced. This option cannot be used
with equalize-contrast. The lower value results in a sharper
image. Default value: 0.3
saturation : Applies to "mantiuk06" operator and "fattal02" operator.
For "mantiuk06"
Saturation correction (values 0-1). The lower value results in
stronger desaturation. Default value: 0.8
For "fattal02"
Amount of color saturation. Suggested range is 0.4 to 0.8. Default value: 0.6.
equalize_contrast : Applies to "mantiuk06" operator.
Use the contrast equalization algorithm. If this option is not
specified, the contrast mapping algorithm will be used. The contrast
equalization algorithm requires scaling parameter that
controls the amount sharpenning, which can range from 0.1 (very
sharp) to 1 (less sharp).
contrast equalization results in very sharp, but also less natural
images. contrast equalization may also enhance noise in low-
quality images.
alpha : Applies to "fattal02".
Set alpha parameter. defines the threshold gradient value (luminance differents of adjacent pixels)
below which the gradients are amplified (detail enhancement) and above which the gradients are attenuated
(global contrast reduction).
Suggested range is 1 to 0.0001. It is reasonable to change parameters by orders of magnitude, so for
instance trying 0.1, 0.01, 0.001 etc. (see paper for details).
beta : Applies to "fattal02".
Set beta parameter. sets the strength of gradient (local contrast) modification. Suggested range is
0.8 to 0.96 (see paper for details). Value of 1 does not change contrasts, values above 1 reverse the
effect: global contrast is stretched and details are attenuated. Values below 0.5 lead to very strong ampli‐
fication of small contrast, so consider using --noise parameter close to 'alpha' value to prevent noise.
noise_reduction : Applies to "fattal02".
Reduces gradient amplification value for gradients close to 0 and reduces noise in the result. defines
gradient value (luminance differents of adjacent pixels) which is treated as noise. Suggested range is 0.0 to
the value of alpha. Default value calculated based on alpha: 0.001*alpha.
brightness : Applies to "reinhard05".
Brightness correction (-8..8), parameter 'f' in paper. Default value: 0.0
chromatic : Applies to "reinhard05".
Amount of chromatic adaptation (von Kries model) (0..1), parameter 'c' in paper. Default value: 0.0
light : Applies to "reinhard05".
Amount of light adaptation adaptation (0..1), parameter 'l' in paper. Default value: 1.0
use_scales: Applies to "reinhard02".
Whether or not the lower/upper scale parameters should be used or determinted automatically.
Default value : false Options : true, false
See http://www.cs.utah.edu/~reinhard/cdrom/ for more information.
bias: Applies to "drago03".
Default value : 0.85 Range : 0 - 1
sigma_s: Applies to "durand02".
Sigma value for spatial kernel.
Default value : 40
sigma_r: Applies to "durand02".
Sigma value for spatial kernel.
Default value : 0.4
base_contrast: Applies to "durand02".
Contrast of the base layer. Default value is 5.0f. Lower value
causes higher contrast compression and results in darker picture
- can help if after tone mapping too many pixels remain satu‐
rated.
Increasing this value will results in brighter and more
'dynamic' picture.
multiplier: Applies to "pattanaik00".
Multiply input values by a multiplier value. Useful if input
data is not calibrated.
Default value: 1.0
use_local: Applies to "pattanaik00".
Use local version of the tone mapping. Time-dependent effects
are cancelled while using local version, global version is used
by default.
Default value : false Options : true, false
use_cone_and_rod: Applies to "pattanaik00".
When set to false, the TMO will attempt to determine the best value for cone and rod.
Default value : false Options : true, false
cone: Applies to "pattanaik00".
Default value: 0.5
rod: Applies to "pattanaik00".
Default value: 0.5
pre_gamma : A boolean value indicating whether or not to apply gamma correction before tonemapping.
pre_gamma_level : Perform gamma correction (input^(1/gamma)). This can be used to convert images from relative luminance or
radiance to pixel values. Default value: 1.0
pre_gamma_invert : Perform inverse gamma correction (input^(gamma)). This can be used to convert images from pixel values to
relative radiance or luminance.
pre_gamma_multiply : Multiply data by this value before gamma correction. Default value: 1
post_gamma : A boolean value indicating whether or not to apply gamma correction after tonemapping.
post_gamma_level : Perform gamma correction (input^(1/gamma)). This can be used to convert images from relative luminance or
radiance to pixel values. Default value: 1.0
post_gamma_invert : Perform inverse gamma correction (input^(gamma)). This can be used to convert images from pixel values to
relative radiance or luminance.
post_gamma_multiply : Multiply data by this value before gamma correction. Default value: 1
filename : The filename for the resulting image. If not specified, one will be randomly generated.
base_url : The base URL where the resulting image should be stored. If not specified the file will be stored in our S3 bucket for 24 hours or more and you will need to download it and place it where you need it.
label : An optional label that you can use to track this job.
thumbnails : An array of one or more thumbnail parameter groups. Please see the "Thumbnail Job" documentation for details.
Once a tonemapping job has been accepted for processing Phocoder will return an immediate response with
details about the output files that will be produced as part of that job.
id : The Phocoder system id for this job. This id may be used to look up job status.
inputs : An array containing a single parameter hash of data about the input for the job.
This returns a single member array instead of a single hash to match the format of the response for HDR jobs, which may have more than one input.
Input attributes are :
id : The Phocoder system id for this input.
tonemapping : A set of tonemapping attributes.
id : The Phocoder system id for this tonemapping. This id can be used to look up the status of this tonemapping.
label : The label supplied when the job was created.
filename : The filename of the tonemapping that will be created.
thumbnails : An array of thumbnail attributes.
id : The Phocoder system id for this thumbnail. This id can be used to look up the status of this thumbnail.
label : The label supplied when the job was created.
filename : The filename of the thumbnail that will be created.
A composite job will take multiple input images and create a
virtual stack of image layers. Each layer has a blending mode and an opacity.
The final composite is the result of flattening all of the layers.
Composite Job Parameters
type : "CompositeJob"
composite : A set of compsite parameters.
Composite parmeters:
auto_normalize : A boolena value indicating whether or not to auto normalize the color levels in the composite.
layers : An array of sets of layer paramertsr.
Layer paremeters:
inputs : The url of the input image.
blending_mode : The blending mode for the layer. Options are
SoftLightCompositeOp,
HardLightCompositeOp,
BumpmapCompositeOp,
ColorBurnCompositeOp,
ColorDodgeCompositeOp,
ColorizeCompositeOp,
CopyBlackCompositeOp,
CopyBlueCompositeOp,
CopyGreenCompositeOp,
CopyRedCompositeOp,
DarkenCompositeOp,
DifferenceCompositeOp,
LightenCompositeOp,
LinearLightCompositeOp,
LuminizeCompositeOp,
MultiplyCompositeOp,
NoCompositeOp,
NormalCompositeOp,
OverCompositeOp,
OverlayCompositeOp,
SaturateCompositeOp, and
ScreenCompositeOp
opacity : The opacity for this layer. Valid range is 0-100.
Once a composite job has been accepted for processing Phocoder will return an immediate response with
details about each output that will be produced as part of that job.
id : The Phocoder system id for this job. This id may be used to look up job status.
composite : A set of composite attributes.
id : The Phocoder system id for this composite. This id can be used to look up the status of this composite.
label : The label supplied when the job was created.
filename : The filename of the composite that will be created.
thumbnails : An array of thumbnail attributes.
id : The Phocoder system id for this thumbnail. This id can be used to look up the status of this thumbnail.
label : The label supplied when the job was created.
filename : The filename of the thumbnail that will be created.