'YOUR_API_SECRET') # Set API secret here
-ENDPOINT = 'https://api.imagga.com/v1'
+ENDPOINT = 'https://api.imagga.com/v2'
FILE_TYPES = ['png', 'jpg', 'jpeg', 'gif']
filename = image_file.name
# Upload the multipart-encoded image with a POST
- # request to the /content endpoint
+ # request to the /uploads endpoint
content_response = requests.post(
- '%s/content' % ENDPOINT,
+ '%s/uploads' % ENDPOINT,
files={filename: image_file})
- # Example /content response:
- # {'status': 'success',
- # 'uploaded': [{'id': '8aa6e7f083c628407895eb55320ac5ad',
- # 'filename': 'example_image.jpg'}]}
- uploaded_files = content_response.json()['uploaded']
+ # Example /uploads response:
+ # "upload_id": "i05e132196706b94b1d85efb5f3SaM1j"
+ uploaded_file = content_response.json()['result']
- # Get the content id of the uploaded file
- content_id = uploaded_files[0]['id']
+ # Get the upload id of the uploaded file
+ upload_id = uploaded_file['upload_id']
-def tag_image(image, content_id=False, verbose=False, language='en'):
+def tag_image(image, upload_id=False, verbose=False, language='en'):
# Using the content id and the content parameter,
# make a GET request to the /tagging endpoint to get
- 'content' if content_id else 'url': image,
+ 'image_upload_id' if upload_id else 'image_url': image,
tagging_response = requests.get(
- '%s/tagging' % ENDPOINT,
return tagging_response.json()
-def extract_colors(image, content_id=False):
+def extract_colors(image, upload_id=False):
- 'content' if content_id else 'url': image,
+ 'image_upoad_id' if upload_id else 'image_url': image,
colors_response = requests.get(
print('[%s / %s] %s uploading' %
(iterator + 1, images_count, image_path))
- content_id = upload_image(image_path)
+ upload_id = upload_image(image_path)
except ArgumentException:
- tag_result = tag_image(content_id, True, verbose, language)
+ tag_result = tag_image(upload_id, True, verbose, language)
results[image_file] = tag_result
- colors_result = extract_colors(content_id, True)
+ colors_result = extract_colors(upload_id, True)