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:
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
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.
You first create an HDR engine. You will then add the input images to that HDR engine in step 2.
https://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°hosting=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);
}
?>
You now add bracketed images one by one to the HDR engine created in step 1.
https://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);
}
?>
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.
https://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 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.
# 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, '/');
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;
?>
$curl = curl_init("https://hdr-photography.com:8081" . $baseURL . "/process?
If you want to track how many credits you have remaining after merging images, you can query the server to find out.
https://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>
https://hdr-photography.com:8081/hdrengines
Creates an HDR engine to which images can be added, merged to HDR and processed with an HDR preset.
The URI of the created HDR engine in the Location header.
Whether the engine will be processing a single image or a bracketed set
Whether to align images when merging them
Which source images, if any, to perform noise reduction on
Whether to remove ghosts when merging the images
Number of bits per channel of the resulting image
The location header contains the URI to access the new HDR engine.
The response body contains more details about the error.
https://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:
If supplied, the URL for a valid image file.
If supplied, the data for the image to be uploaded.
Either the URL or image parameter must be supplied.
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.
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".
https://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 2: Upload an XMP file containing a custom preset in the custom-preset parameter in the request body.
The resulting image in the body of the response, in JPEG or TIFF format.
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'.
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.
The format to return the result image in.
The image in JPEG or TIFF format is returned in the body of the response.
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.
https://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/
The created 32-bit HDR image in the body of the response, in OpenEXR format.
The HDR image in OpenEXR format is returned as the response.
Less than two images were loaded into the engine.
https://hdr-photography.com:8081/usage
Queries the status of the current subscription.
The total number of credits in the current subscription, and the number remaining.
The subscription details are returned as the response.