Autoenhance.ai
  • Overview
  • Getting Started
    • Obtaining an API key
    • Quickstart
      • Single Image
      • HDR Brackets
    • Code Examples
      • JavaScript
        • Uploading Single Bracket
        • Uploading HDR
        • Uploading 360
      • API Integrations Repository
  • SDKs
    • Web (Beta)
      • Changelog
    • JavaScript
      • Changelog
    • Python
      • Changelog
  • File & Camera Guidelines
    • File Formats
    • Metadata
    • 360
    • Lens Correction
  • Images
    • Managing Images
      • Creating & Uploading
      • Reprocessing
      • Retrieveing
      • Deleting
      • Reporting
    • Settings
      • Enhancement Style
      • Sky Replacement
      • Lens Correction
      • Vertical Correction
      • Window Pull
      • Auto Privacy
      • Usage Example
    • Downloading Images
      • Original
      • Preview
      • Enhanced
  • Orders
    • Managing Orders
      • Creating
      • Editing
      • Retrieving
      • Listing and Pagination
      • Deleting
    • Grouping Brackets and Processing Orders
  • Webhooks
  • API Versions
  • AI Versions
  • Links
    • API Specification
    • Support
Powered by GitBook
On this page
  1. Images
  2. Settings

Usage Example

PreviousAuto PrivacyNextDownloading Images

Last updated 10 months ago

Since there's a lot of combinations of the preferences that you can use, so we've prepared an code example that will help you understand how to work with them.

Let's repeat the process of creating and uploading images, but with all of the .

You can freely edit the preferences in any way you want. The only requirement is to follow our guide or , which will help you find the appropriate values.

const apiKey = 'YOUR_API_KEY';
const preferences = {
    enhance_type: 'property',
    sky_replacement: true,
    cloud_type: 'CLEAR',
    vertical_correction: true,
    auto_privacy: true,
};

const createImage = async (apiKey, preferences) => {
    const createImageResponse = await fetch('https://api.autoenhance.ai/v3/images/', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'x-api-key': apiKey,
        },
        body: JSON.stringify({
            image_name: 'your-image-name',
            contentType: 'image/jpeg',
            ...preferences
        }),
    });

    const { s3PutObjectUrl, order_id, image_id } = await createImageResponse.json();

    const uploadImageResponse = await fetch(s3PutObjectUrl, {
        method: 'PUT',
        headers: {
            'Content-Type': 'image/jpeg',
            'x-api-key': apiKey,
        },
        body: blob,
    });

    if (uploadImageResponse.ok) {
        console.log('Image successfully uploaded');
    } else {
        console.log('Error uploading image');
    }
};
import requests

api_key = 'YOUR_API_KEY'
preferences = {
    'enhance_type': 'property',
    'sky_replacement': True,
    'cloud_type': 'CLEAR',
    'vertical_correction': True,
    'auto_privacy': True,
}

def create_image(api_key, preferences, image_path):
    create_image_response = requests.post(
        'https://api.autoenhance.ai/v3/images/',
        headers={
            'Content-Type': 'application/json',
            'x-api-key': api_key,
        },
        json={
            'image_name': 'your-image-name',
            'contentType': 'image/jpeg',
            **preferences
        }
    )

    if create_image_response.status_code != 200:
        print('Error creating image')
        return

    create_image_data = create_image_response.json()
    s3_put_object_url = create_image_data['s3PutObjectUrl']
    order_id = create_image_data['order_id']
    image_id = create_image_data['image_id']

    with open(image_path, 'rb') as image_file:
        upload_image_response = requests.put(
            s3_put_object_url,
            headers={
                'Content-Type': 'image/jpeg',
                'x-api-key': api_key,
            },
            data=image_file
        )

    if upload_image_response.status_code == 200:
        print('Image successfully uploaded')
    else:
        print('Error uploading image')
$api_key = 'YOUR_API_KEY';
$preferences = array(
    'enhance_type' => 'property',
    'sky_replacement' => true,
    'cloud_type' => 'CLEAR',
    'vertical_correction' => true,
    'auto_privacy' => true
);

function create_image($api_key, $preferences) {
    $data = array_merge(array(
        'image_name' => 'your-image-name',
        'contentType' => 'image/jpeg'
    ), $preferences);

    $url = "https://api.autoenhance.ai/v3/images/";
    $options = array(
        'http' => array(
            'header'  => "Content-Type: application/json\r\n" .
                         "x-api-key: $api_key",
            'method'  => 'POST',
            'content' => json_encode($data),
        ),
    );
    $context  = stream_context_create($options);
    $result = file_get_contents($url, false, $context);

    if ($result === FALSE) {
        return 'Error creating image';
    }

    $response = json_decode($result, true);
    $s3PutObjectUrl = $response['s3PutObjectUrl'];

    $image_path = '/path/to/your/image.jpg';
    $image_data = file_get_contents($image_path);
    $upload_options = array(
        'http' => array(
            'header'  => "Content-Type: image/jpeg\r\n" .
                         "x-api-key: $api_key",
            'method'  => 'PUT',
            'content' => $image_data,
        ),
    );
    $upload_context  = stream_context_create($upload_options);
    $upload_result = file_get_contents($s3PutObjectUrl, false, $upload_context);

    if ($upload_result === FALSE) {
        return 'Error uploading image';
    }

    return 'Image successfully uploaded';
}
Create the image

curl -X POST \
  https://api.autoenhance.ai/v3/images/ \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
        "image_name": "your-image-name",
        "contentType": "image/jpeg",
        "enhance_type": "property",
        "sky_replacement": true,
        "cloud_type": "CLEAR",
        "vertical_correction": true,
        "auto_privacy": true
    }'
    
Upload the image

curl -X PUT \
  S3_PUT_OBJECT_URL \
  -H 'Content-Type: image/jpeg' \
  -H 'x-api-key: YOUR_API_KEY' \
  --data-binary @path/to/your/image.jpg

Basic Enhancements
Image Settings
API specification