In this guide we will be walking you through how to enhance your first HDR image, you will:
Learn how to register the fact you want to upload 2 or more brackets for an HDR image with Autoenhance
Upload your image file for each bracket to Autoenhance using the provided endpoint received after registering your image
Tell Autoenhance you have finished uploading your brackets and you are ready for it to start merging them.
Checking the status of the order
Downloading the final enhanced HDR image
This guide assumes the following:
You already have an API key, if you don't have one please see our guide here.
That you have already uploaded a single bracket, if you haven't we reccomend you follow our guide here
1. Creating an Order
Before we can upload some brackets we need to create an order for them live so that Autoenhance understands that they are related to each other. To do this we issue a POST request to the /orders endpoint.
Now we need to register and upload the file for each bracket, to do this we create a POST request to the dedicated /brackets endpoint and provide the order_id we got from the orders endpoint. This is so that Autoenhance knows that these brackets belong together and are eligible to be merged together.
You can provide the name of each bracket in the name property, the final image takes the name from the first bracket and this can be a useful way to cross-reference which brackets you have uploaded
Create image
curl -X POST \
https://api.autoenhance.ai/v3/brackets/ \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{
"order_id": "YOUR_ORDER_ID",
"name": "your-image-name.jpg",
}'
Upload Image
Replace UPLOAD_URL with the value of s3PutObjectUrl received from the previous response
curl -X PUT \
UPLOAD_URL \
-H 'Content-Type: application/octet-stream' \
-H 'x-api-key: YOUR_API_KEY' \
--data-binary @path/to/your/image.jpg
2. Grouping and enhancing your brackets
Once you have uploaded all of your brackets, you are now ready to request Autoenhance start grouping them into images and then enhancing them.
There are three options depending on your use case.
By default when you call the /orders/<order_id>/process endpoint, Autoenhance will analyse the metadata and visual similarity of your brackets. They will be automatically grouped together and returned as a single HDR image.
const uploadAllBrackets = async (apiKey, files, orderId) => {
const promises = files.map(file => uploadBracket(orderId, apiKey, file));
await Promise.all(promises);
const mergeResponse = await fetch(
`https://api.autoenhance.ai/v3/orders/${orderId}/process`,
{
method: "POST",
headers: {
"x-api-key": apiKey,
}
}
);
// This is an URL to our web application where you can
// take a look at your order, you don't need to return it.
return `https://app.autoenhance.ai/orders/${orderId}`
};
const apiKey = YOUR_API_KEY;
const files = [File, File, File] // Array of Files or Blobs
const orderId = "YOUR_UNIQUE_ORDER_ID" // Ideally generated with uuidv4
uploadAllBrackets(apiKey, files, orderId)
def upload_all_brackets(api_key, files, order_id):
for file in files:
upload_bracket(order_id, api_key, file)
merge_url = f"https://api.autoenhance.ai/v3/orders/{order_id}/process"
merge_headers = {"x-api-key": api_key}
merge_response = requests.post(merge_url, headers=merge_headers)
if merge_response.status_code != 200:
raise Exception(f"Failed to merge order: {merge_response.text}")
#This is an URL to our web application where you can
#take a look at your order, you don't need to return it.
return f"https://app.autoenhance.ai/orders/{order_id}"
api_key = "YOUR_API_KEY"
files = [open('file1.jpg', 'rb'), open('file2.jpg', 'rb'), open('file3.jpg', 'rb')] # List of file objects
order_id = "YOUR_UNIQUE_ORDER_ID" # Ideally generated with uuid.uuid4()
order_url = upload_all_brackets(api_key, files, order_id)
# Close the files after uploading
for file in files:
file.close()
print(order_url)
function upload_all_brackets($api_key, $files, $order_id) {
$promises = array_map(function($file) use ($order_id, $api_key) {
return upload_bracket($order_id, $api_key, $file);
}, $files);
$merge_url = "https://api.autoenhance.ai/v3/orders/$order_id/process";
$merge_options = array(
'http' => array(
'header' => "x-api-key: $api_key",
'method' => 'POST',
),
);
$merge_context = stream_context_create($merge_options);
$merge_result = file_get_contents($merge_url, false, $merge_context);
if ($merge_result === FALSE) {
return 'Error merging brackets';
}
// Return the URL to the web application
return "https://app.autoenhance.ai/orders/$order_id";
}
$api_key = "YOUR_API_KEY";
$files = [/* Array of Files or Blobs */];
$order_id = "YOUR_UNIQUE_ORDER_ID";
upload_all_brackets($api_key, $files, $order_id);
Upload each bracket
for file in file1 file2 file3; do
# Replace file1, file2, file3 with the actual paths to your files
curl -X POST \
https://api.autoenhance.ai/v3/images/ \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{
"order_id": "YOUR_ORDER_ID",
"image_name": "your-image-name.jpg",
"contentType": "image/jpeg",
"hdr": true
}'
done
Merge brackets
curl -X POST \
https://api.autoenhance.ai/v3/orders/YOUR_ORDER_ID/process \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY'
In cases where you already know each time how many brackets you shot you can provide the /orders/<order_id>/process endpoint the number_of_brackets_per_image field with a number - in this case Autoenhance will sort your brackets by the time they were shot using their metadata and group your brackets based on this i.e if you set this to 3 then every 3 brackets will be grouped into one image
const uploadAllBrackets = async (apiKey, files, orderId) => {
const promises = files.map(file => uploadBracket(orderId, apiKey, file));
await Promise.all(promises);
const mergeResponse = await fetch(
`https://api.autoenhance.ai/v3/orders/${orderId}/process`,
{
method: "POST",
headers: {
"x-api-key": apiKey,
},
body: {
number_of_brackets_per_image: 5
}
}
);
// This is an URL to our web application where you can
// take a look at your order, you don't need to return it.
return `https://app.autoenhance.ai/orders/${orderId}`
};
const apiKey = YOUR_API_KEY;
const files = [File, File, File] // Array of Files or Blobs
const orderId = "YOUR_UNIQUE_ORDER_ID" // Ideally generated with uuidv4
uploadAllBrackets(apiKey, files, orderId)
def upload_all_brackets(api_key, files, order_id):
for file in files:
upload_bracket(order_id, api_key, file)
merge_url = f"https://api.autoenhance.ai/v3/orders/{order_id}/process"
merge_headers = {"x-api-key": api_key}
merge_response = requests.post(merge_url, headers=merge_headers, json={
"number_of_brackets_per_image": 5
})
if merge_response.status_code != 200:
raise Exception(f"Failed to merge order: {merge_response.text}")
#This is an URL to our web application where you can
#take a look at your order, you don't need to return it.
return f"https://app.autoenhance.ai/orders/{order_id}"
api_key = "YOUR_API_KEY"
files = [open('file1.jpg', 'rb'), open('file2.jpg', 'rb'), open('file3.jpg', 'rb')] # List of file objects
order_id = "YOUR_UNIQUE_ORDER_ID" # Ideally generated with uuid.uuid4()
order_url = upload_all_brackets(api_key, files, order_id)
# Close the files after uploading
for file in files:
file.close()
print(order_url)
function upload_all_brackets($api_key, $files, $order_id) {
$promises = array_map(function($file) use ($order_id, $api_key) {
return upload_bracket($order_id, $api_key, $file);
}, $files);
$merge_url = "https://api.autoenhance.ai/v3/orders/$order_id/process";
$merge_options = array(
'http' => array(
'header' => "x-api-key: $api_key",
'method' => 'POST',
'content' => json_encode(array('number_of_brackets_per_image' => 5))
)
),
);
$merge_context = stream_context_create($merge_options);
$merge_result = file_get_contents($merge_url, false, $merge_context);
if ($merge_result === FALSE) {
return 'Error merging brackets';
}
// Return the URL to the web application
return "https://app.autoenhance.ai/orders/$order_id";
}
$api_key = "YOUR_API_KEY";
$files = [/* Array of Files or Blobs */];
$order_id = "YOUR_UNIQUE_ORDER_ID";
upload_all_brackets($api_key, $files, $order_id);
Upload each bracket
for file in file1 file2 file3; do
# Replace file1, file2, file3 with the actual paths to your files
curl -X POST \
https://api.autoenhance.ai/v3/images/ \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{
"order_id": "YOUR_ORDER_ID",
"image_name": "your-image-name.jpg",
"contentType": "image/jpeg",
"hdr": true
}'
done
Merge brackets
curl -X POST \
https://api.autoenhance.ai/v3/orders/YOUR_ORDER_ID/process \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY'
=d '{ "number_of_brackets_per_image": 5"}'
In cases where you have already grouped your brackets, you can send these groups to Autoenhance by passing an "images" array , each item should be an object containing a "bracket_ids" fields containing another array with the ID for each bracket you registered earlier.
const uploadAllBrackets = async (apiKey, files, orderId) => {
const promises = files.map(file => uploadBracket(orderId, apiKey, file));
const results = await Promise.all(promises);
const bracketIds = results.map(result => result.bracket_id);
const mergeResponse = await fetch(
`https://api.autoenhance.ai/v3/orders/${orderId}/process`,
{
method: "POST",
headers: {
"x-api-key": apiKey,
},
body: {
images: [
{
{
"bracket_ids": bracketIds
}
}
]
}
}
);
// This is an URL to our web application where you can
// take a look at your order, you don't need to return it.
return `https://app.autoenhance.ai/orders/${orderId}`
};
const apiKey = YOUR_API_KEY;
const files = [File, File, File] // Array of Files or Blobs
const orderId = "YOUR_UNIQUE_ORDER_ID" // Ideally generated with uuidv4
uploadAllBrackets(apiKey, files, orderId)
def upload_all_brackets(api_key, files, order_id):
bracket_ids = []
for file in files:
bracket_ids.append(upload_bracket(order_id, api_key, file))
merge_url = f"https://api.autoenhance.ai/v3/orders/{order_id}/process"
merge_headers = {"x-api-key": api_key}
merge_response = requests.post(merge_url, headers=merge_headers, json={
"images": [
{
"bracket_ids": bracket_ids
}
]
})
if merge_response.status_code != 200:
raise Exception(f"Failed to merge order: {merge_response.text}")
#This is an URL to our web application where you can
#take a look at your order, you don't need to return it.
return f"https://app.autoenhance.ai/orders/{order_id}"
api_key = "YOUR_API_KEY"
files = [open('file1.jpg', 'rb'), open('file2.jpg', 'rb'), open('file3.jpg', 'rb')] # List of file objects
order_id = "YOUR_UNIQUE_ORDER_ID" # Ideally generated with uuid.uuid4()
order_url = upload_all_brackets(api_key, files, order_id)
# Close the files after uploading
for file in files:
file.close()
print(order_url)
Upload each bracket
BRACKET_IDS=()
for file in file1 file2 file3; do
# Replace file1, file2, file3 with the actual paths to your files
RESPONSE=$(curl -X POST \
https://api.autoenhance.ai/v3/brackets/ \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY' \
-d '{
"order_id": "YOUR_ORDER_ID",
"name": "your-image-name.jpg"
}')
# You will need "jq" installed
BRACKET_ID=$(echo "$RESPONSE" | jq -r '.bracket_id')
# Append to array if not null
if [ "$BRACKET_ID" != "null" ]; then
BRACKET_IDS+=("\"$BRACKET_ID\"")
fi
done
Merge brackets
# Build JSON array from collected bracket IDs
BRACKET_IDS_JSON=$(printf ", %s" "${BRACKET_IDS[@]}")
BRACKET_IDS_JSON="[${BRACKET_IDS_JSON:2}]" # Remove leading comma
MERGE_PAYLOAD=$(cat <<EOF
{
"images": [
{
"bracket_ids": $BRACKET_IDS_JSON
}
]
}
EOF
)
echo "Sending merge request..."
curl -X POST \
https://api.autoenhance.ai/v3/orders/$ORDER_ID/process \
-H "Content-Type: application/json" \
-H "x-api-key: $API_KEY" \
-d "$MERGE_PAYLOAD"
3. Checking the order status
Grouping brackets for each HDR image can take between 10 seconds to 5 minutes to complete depending on the number of brackets that need grouping.
We can check when this has finished by calling the GET /order/<order_id> endpoint and reading the is_merging and is_processing fields. Whilst the AI is still grouping the orders is_merging will be true, however if you want to display the progress of this grouping to customers then the images field will gradually be populated with images.
As each image is grouped the AI will automatically start enhancing them, you can check the status of each image individually using their status fields. Once all images have been enhanced the is_processing field for the order will change to false which can be used to stop showing any processing indicators to your end user.
You should always check your order status before downloading your images. In this case, we need to check whether the order has falsy values for is_merging and is_processing or not. You can start downloading all of your images once both of them are false.
Check image status
curl -X GET \
https://api.autoenhance.ai/v3/images/ID_OF_YOUR_IMAGE \
-H 'Content-Type: application/json'
Download image
curl -X GET \
https://api.autoenhance.ai/v3/images/ID_OF_YOUR_IMAGE/enhanced \
-H 'Content-Type: application/json' \
-H 'x-api-key: YOUR_API_KEY'
This example uses the least possible amount of properties in order to create an image. If you want to apply any kind of preferences to it, visit our Image Settings page to find out more about them. Once you are familiar with them, simply add them in the body of the POST request to our API.