Deep Image AI makes it easy to process images through a simple API. Follow these steps to use it correctly and avoid common mistakes.
1. Process an Image
There are two processing methods.
The process method sends an image for processing and immediately returns job id.
The process_result method sends an image and waits up to 25 seconds for the result. If the image is processed in time, you get a direct link to the final image.
Sending an image with process method and periodically checking the result
import time
import json
from pathlib import Path
from urllib.request import urlretrieve
# using requests library
import requests
API_KEY = REPLACE_WITH_YOUR_API_KEY
headers = {
'x-api-key': API_KEY,
}
data = {
"enhancements": ["denoise", "deblur", "light"],
"width": 2000
}
data_dumped = {"parameters": json.dumps(data)}
with open(YOUR_LOCAL_FILE_TO_SEND, 'rb') as f:
response = requests.post('https://deep-image.ai/rest_api/process', headers=headers,
files={'image': f},
data=data_dumped)
if response.status_code == 200:
response_json = response.json()
job_id = response_json["job"]
result_status = "received"
while result_status in ['received', 'in_progress', 'not_started']:
response = requests.get(f'https://deep-image.ai/rest_api/result/{job_id}',
headers=headers)
response_json = response.json()
result_status = response_json['status']
time.sleep(1)
if result_status == 'complete':
p = Path(response_json['result_url'])
urlretrieve(response_json['result_url'], p.name)
If you don’t get a result URL, don’t send the image again! Use the job ID to check the status instead.
2. Get results faster with webhooks (Recommended)
Instead of checking the status manually, you can set up a webhook. This means Deep Image AI will send you the result automatically when the image is ready.
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/deep-image-webhook", methods=["POST"])
def webhook():
data = request.json
print("Image is ready:", data["result_url"])
return jsonify({"status": "received"}), 200
app.run(port=5000)
3. Automate Workflows with Zapier Integration
Zapier enables you to connect Deep Image AI with thousands of other applications, automating tasks seamlessly. For example, you can set up a workflow where images uploaded to a specific folder in Google Drive are automatically enhanced using Deep Image AI.
✅ Example: Automating Image Enhancement with Zapier
Trigger: When a new image is added to a designated Google Drive folder.
Action: Use Deep Image AI to enhance the image automatically.
This setup ensures that every image added to your folder is processed without manual intervention.
4. Enhance Automation with Make (Integromat) Integration
Make allows you to build and automate complex workflows by connecting Deep Image AI with numerous other apps. For instance, you can create a scenario where images from a Telegram Bot are automatically processed and stored in Dropbox.
✅ Example: Processing Images via Make
Trigger: Receive a new image through a Telegram Bot.
Action: Process the image using Deep Image AI's enhancement features.
Action: Save the enhanced image to a Dropbox folder.
This workflow automates the entire process from image reception to storage.