Photomatix API Documentation (Beta)

Introduction

The Photomatix Online API lets you integrate Photomatix HDR image processing into your application or workflow. Sending HTTP requests to the API allows you to:

  • Merge exposure bracketed photos to a 32-bit HDR image, process it with an HDR preset and save the result as a JPEG or TIFF file.
  • Merge exposure bracketed photos to a 32-bit HDR image and save it as an EXR file.
  • Process a single photo with an HDR preset and save the result as JPEG or TIFF file.

You will need to provide an API key for each request you send.

If you don't have an API key and would like to try the beta, please contact us at support@hdrsoft.com to request a beta test API key.

NOTE

The Photomatix online API is currently in beta release testing.

Please report any issue you find while testing the API to bugs@hdrsoft.com

Getting Started with an Example

Follow the steps below to merge bracketed photos to HDR, process the merged image with an HDR preset and save the resulting image.

Each step corresponds to an API call. Step 1 creates an HDR engine, step 2 adds the input bracketed photos to the HDR engine and step 3 merges the input photos, processes them with an HDR preset and saves the resulting image.

The parameters for the requests are described in the API reference.

Step 1: Set up an HDR engine

You first create an HDR engine. You will then add the input images to that HDR engine in step 2.

POSThttps://hdr-photography.com:8081/hdrengines

The request returns the URI of the created HDR engine.

The parameters specify the options for merging the input images. You can use the controls below to dynamically adjust the parameters in the code snippet.

# Replace with your API key
APIKEY="YOUR_API_KEY"

engineLocation="$(curl -i -X POST -H "x-pm-token: $APIKEY" "https://hdr-photography.com:8081/hdrengines?type=multi&alignment=yes&deghosting=off&noise-reduction=none&output-bit-depth=8" | grep Location: | sed 's/\r//' | awk '{ print $2 }')"
if [ "$engineLocation" = "" ]; then
  echo "HDR Engine creation failed"
  exit 1
fi
  
<?php
//Replace with your API key
$apiKey = "YOUR_API_KEY";

function getLocation($response) {
  $headerLines = explode("\r\n", $response);
  foreach ($headerLines as $line)
    if (strpos($line, 'Location:') !== false)
      return trim(str_replace('Location:', '', $line));
  return "";
}   

function getJsonResponse($curl, $response) {
  if ($response === false) return null;
  $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
  $body = substr($response, $headerSize);
  return json_decode($body, true);
}   

$curl = curl_init("https://hdr-photography.com:8081/hdrengines?type=multi");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-pm-token: " . $apiKey));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, true);

$response = curl_exec($curl);
$jsonResponse = getJsonResponse($curl, $response);

if ($response === false)
    die("Curl error: " . curl_error($curl));
curl_close($curl);

$engineLocation = getLocation($response);
if ($engineLocation == "") {
    $error = "Couldn't create HDR engine";
    if (isset($jsonResponse['error']['message']))
        $error .= ": " . $jsonResponse['error']['message'];
    die($error);
}

?>

Step 2: Add bracketed images to the HDR engine

You now add bracketed images one by one to the HDR engine created in step 1.

POSThttps://hdr-photography.com:8081/hdrengines/engineID/images/filename

engineID is the HDR engine returned in step 1.

filename is the file name of the added image.

You can add the image in two ways: either uploading it by including its data in the image parameter in the body of the POST request (shown in the code below), or providing the location of the image file in the URL parameter in the body.

# Note: This code snippet should appear below the code for step 1, in the same script

# Replace with your API key
APIKEY="YOUR_API_KEY"

# Replace with the path to the folder where your bracketed images are
imageSourceDir="/path/to/image/dir"

for image in "$imageSourceDir"/*; do
  if [ -f "$image" ]; then
    baseName="$(basename "$image")"
    # The $engineLocation variable was set in step 1
    curl -i -X "POST" -H "x-pm-token: $APIKEY" "https://hdr-photography.com:8081$engineLocation/images/$baseName"  -F "image=@$image"
  fi
done
  
<?php

//Note: This code snippet should appear below the code for step 1, in the same script

//Replace with your API key
$apiKey = "YOUR_API_KEY";

 // Replace with the path to the folder where your bracketed images are
$imageSourceDir = "/path/to/image/dir";

// The $engineLocation variable that was set in step 1
$baseURL = rtrim($engineLocation, '/');

$imagesToProcess = scandir($imageSourceDir);

// Loop through each file in the folder
// All images in the folder will be loaded and merged - Adjust the loop if you want to merge one set of files at a time
foreach ($imagesToProcess as $image) {
    $filePath = $imageSourceDir . DIRECTORY_SEPARATOR . $image;
    if (!is_file($filePath)) continue;
    $curl = curl_init("https://hdr-photography.com:8081" . $baseURL . "/images/" . basename($image));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-pm-token: " . $apiKey));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, array('image' => file_get_contents($filePath)));
    curl_setopt($curl, CURLOPT_HEADER, true);

    $response = curl_exec($curl);
    $jsonResponse = getJsonResponse($curl, $response);

    if ($response === false)
        die("Couldn't add file: " . curl_error($curl));

    if (($respCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE)) != 201) {
        $jsonResponse = getJsonResponse($curl, $response);
        if (isset($jsonResponse['error']['message']))
            die("Failed to add file: " . $jsonResponse['error']['message']);
        else
            die("Failed to add file: got reponse code " . $respCode);
    }
    curl_close($curl);
}

?>

Step 3: Merge to HDR and process with a preset

The HDR engine you set up in step 1 is now ready to merge the images you added in step 2. The last step merges the images to HDR, processes them with an HDR preset and returns the resulting image.

POSThttps://hdr-photography.com:8081/hdrengines/engineID/process

The request returns the resulting image in the body of the response.

The request has two parameters:

  • The format parameter sets the format of the resulting image and can be either jpg or tiff.
  • The preset (or custom-preset) parameter sets the HDR preset you would like to apply. The preset determines the style of the resulting image.

    You can either specify the name of a Photomatix built-in preset (via the preset parameter) or upload a custom preset you created in Photomatix and saved as XMP file (via the custom-preset parameter)

The code snippet below sets the preset parameter to specify built-in presets. 'Detailed' is the default tone mapping preset. Other popular presets are 'Natural', the default fusion preset, and 'Interior' the default preset for real estate photography.

The dropdown menu below lists available built-in presets. Selecting one of them dynamically adjusts the preset parameter in the code.

Select an HDR preset:  
list filter: 
Return the resulting image as:  
# Note: This code snippet should appear below the code for step 1 and step 2, in the same script

# Replace with your API key
APIKEY="YOUR_API_KEY"

# The $engineLocation variable was set in step 1
curl -X "POST" -o ResultImage.jpg -H "x-pm-token: $APIKEY" "https://hdr-photography.com:8081$engineLocation/process?preset=Detailed"
  
<?php

//Note: This code snippet should appear below the code for step 1 and step 2, in the same script

//Replace with your API key
$apiKey = "YOUR_API_KEY";

//The $engineLocation variable that was set in step 1
$baseURL = rtrim($engineLocation, '/');

$curl = curl_init("https://hdr-photography.com:8081" . $baseURL . "/process?preset=Detailed");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-pm-token: " . $apiKey));
curl_setopt($curl, CURLOPT_POST, true);
$response = curl_exec($curl);
$respCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);

if ($response === false)
    die("Couldn't process with preset: " . curl_error($curl));

if ($respCode != 201) {
    $jsonResponse = getJsonResponse($curl, $response);
    if (isset($jsonResponse['error']['message']))
        die("Failed to process bracketed set: " . $jsonResponse['error']['message']);
    else
        die("Failed to process bracketed set: got response code " . $respCode);
}

curl_close($curl);

// Processed image is in $response
header("Content-Type: image/jpeg");
echo $response;

?>

Querying credits

If you want to track how many credits you have remaining after merging images, you can query the server to find out.

GEThttps://hdr-photography.com:8081/usage

The request returns a JSON response with the number of credits remaining , as well as the total amount originally allocated.

# Note: This code snippet is not dependent on any previous snippets

# Replace with your API key
APIKEY="YOUR_API_KEY"
curl -i -H "x-pm-token: $APIKEY" "https://hdr-photography.com:8081/usage"
  
<?php

// Note: This code snippet is not dependent on any previous snippets


// Replace with your API key
$apiKey = "YOUR_API_KEY";

function getJsonResponse($curl, $response) {
  if ($response === false) return null;
  $headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
  $body = substr($response, $headerSize);
  return json_decode($body, true);
}

$curl = curl_init("https://hdr-photography.com:8081/usage");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-pm-token: " . $apiKey));
curl_setopt($curl, CURLOPT_HEADER, true);

$response = curl_exec($curl);
$respCode = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
$jsonResponse = getJsonResponse($curl, $response);

?>

<html>
<head>
  <title>Usage details</title>
</head>
<body>

<?php

if ($response === false || $respCode != 200) {
    print("<h1>Error</h1><p>Unable to fetch details for current subscription");
    if (isset($jsonResponse['error']['message']))
        print(": " . $jsonResponse['error']['message']);
    print("</p>");
}
else {
  print("<h1>Subscription details</h1>");
  print("<p>Subscription credits total: " . $jsonResponse['data']['totalCredits'] . "</p>");
  print("<p>Subscription credits remaining: " . $jsonResponse['data']['creditsRemaining'] . "</p>");
}

?>

</body>
</html>

API Reference

Create a new HDR engine

POSThttps://hdr-photography.com:8081/hdrengines

Creates an HDR engine to which images can be added, merged to HDR and processed with an HDR preset.

Returns

The URI of the created HDR engine in the Location header.

Parameters
type
string

Whether the engine will be processing a single image or a bracketed set

multi
The engine will be merging and processing multiple images
single
The engine will be processing a single image
alignment
string

Whether to align images when merging them

yes
Align images (Default)
no
Don't align images
noise-reduction
string

Which source images, if any, to perform noise reduction on

none
No noise reduction (Default)
all
Noise reduction on all images
underexposed
Noise reduction on underexposed images
normal-underexposed
Noise reduction on normal exposure and underexposed images
deghosting
string

Whether to remove ghosts when merging the images

off
No ghost removal (Default)
on
Automatically remove ghosts
output-bit-depth
integer

Number of bits per channel of the resulting image

8
(Default)
16
Response Codes
201
success
The HDR engine has been created

The location header contains the URI to access the new HDR engine.

400
error
Invalid parameter or parameter value

The response body contains more details about the error.

401
error
Invalid API key or credits exhausted
500
error
The server has insufficient resources
Example Responses
Success response
{ "data": { "location": "/hdrengines/0", "message": "Engine created" } }
Invalid parameter
{ "error": { "detail": "The output-bit-depth parameter must be 8 or 16", "message": "Invalid parameter" } }

Add an image to an HDR engine

POSThttps://hdr-photography.com:8081/hdrengines/engineID/images/filename

Loads an image into an engine.

engineID must be a valid HDR engine returned from a post request to /hdrengines/

filename is the name of the file uploaded. The extension is used to determine the type of the file, and must match what was uploaded.

You have two options for supplying the image:

  • Option 1: Upload the image by including its data in the image parameter in the body of the POST request. The image can be in JPEG or TIFF format, as well as many camera RAW formats.
  • Option 2: Provide the location of the image file in the URL parameter in the request body.
Parameters
URL
string
optional

If supplied, the URL for a valid image file.

image
binary
optional

If supplied, the data for the image to be uploaded.

Either the URL or image parameter must be supplied.

raw-color-temp
integer
optional

Adjusts the white balance of the image when the uploaded image is in RAW format.

If the parameter is not supplied, the white balance is read from the EXIF metadata.

Response Codes
201
success
The image has been loaded
400
error
Invalid parameter or incorrect image

If there is an invalid parameter, the response body contains more details about the error.

If there is an incorrect image, the error message describes the type of error which could be: "Missing image or invalid image format", "The image has already been added", "Too many images added" or "Image is larger than the maximum size".

401
error
Invalid API key or credits exhausted
404
error
Invalid engine ID
500
error
The server has insufficient resources
Example Responses
Success response
{ "data": { "message": "Image created" } }
Incorrect URL
{ "error": { "detail": "Unable to load image URL: URL was not found on the server.", "message": "Error adding image" } }

Process with an HDR preset

POSThttps://hdr-photography.com:8081/hdrengines/engineID/process

Merges the images that have been added to the engine, processes them with an HDR preset and returns the resulting image as JPEG or TIFF.

If only one image has been added to the engine, processes that image with an HDR preset and returns the adjuted image as JPEG or TIFF.

engineID must be a valid HDR engine returned from a post request to /hdrengines/

You have two options for specifying the HDR preset to use:

  • Option 1: Pass the name of a Photomatix built-in preset in the preset parameter.
  • Option 2: Upload an XMP file containing a custom preset in the custom-preset parameter in the request body.

Returns

The resulting image in the body of the response, in JPEG or TIFF format.

Parameters
preset
string

If supplied, the name of a Photomatix built-in preset.

The preset determines the style of the resulting image. 'Detailed' is the default tone mapping preset. Other popular presets are 'Natural', the default fusion preset, and 'Interior' the default preset for real estate photography.

The preset parameter is case insensitive but shouldn't include spaces. For instance, the parameter for the Photomatix preset named 'Interior 2' should be set as 'Interior2' or 'interior2'.

custom-preset
XMP data

If supplied, the data for a Photomatix preset file.

The preset determines the style of the resulting image. You can use the Photomatix Pro trial for free to create and save HDR settings in a custom XMP preset file.

Either the preset or custom-preset parameter must be supplied.

format
string

The format to return the result image in.

jpg
(Default)
tiff
Response Codes
201
success
The image has been created

The image in JPEG or TIFF format is returned in the body of the response.

400
error
Invalid parameter or missing images

Less than two images were loaded into the engine if the 'type' parameter of the engine was set to 'multi', or no image was loaded when the 'type' parameter was set to 'single'.

In the case of an invalid parameter, the response body contains more details about the error.

401
error
Invalid API key or credits exhausted
404
error
Invalid engine ID or unknown preset
500
error
The server has insufficient resources
Example Responses
Success response
Response is the image data.
Unknown preset
{ "error": { "detail": "The built in preset you supplied was not found", "message": "Unknown preset" } }

Create a 32-bit HDR image

POSThttps://hdr-photography.com:8081/hdrengines/engineID/create-hdr

Merges the images that have been added to the engine into a 32-bit HDR image.

engineID must be a valid HDR engine returned from a post request to /hdrengines/

Returns

The created 32-bit HDR image in the body of the response, in OpenEXR format.

Response Codes
201
success
The HDR image has been created

The HDR image in OpenEXR format is returned as the response.

400
error
Missing images

Less than two images were loaded into the engine.

401
error
Invalid API key or credits exhausted
404
error
Invalid engine ID
500
error
The server has insufficient resources
Example Responses
Success response
Response is the image data.
Too few images
{ "error": { "detail": "You must have at least two images to create a 32-bit HDR image.", "message": "Too few images" } }

Query subscription details

GEThttps://hdr-photography.com:8081/usage

Queries the status of the current subscription.

Returns

The total number of credits in the current subscription, and the number remaining.

Response Codes
200
success
The query was successful

The subscription details are returned as the response.

401
error
Invalid API key
500
error
An internal error occurred querying the subscription.
Example Responses
Success response
{ "data": { "creditsRemaining": 4903, "totalCredits": 5000 } }
Invalid API key
{ "error": { "detail": "You supplied an invalid API key.", "message": "Invalid API key" } }