How to process images from a local directory
Step 1: Calling the API
import requests
API_KEY = "REPLACE_WITH_YOUR_API_KEY"
def process_image(input_image_path, output_image_path):
try:
url = "https://image-api.photoroom.com/v2/edit"
with open(input_image_path, 'rb') as image_file:
files = { "imageFile": image_file }
headers = {
"Accept": "image/png, application/json",
"x-api-key": API_KEY
}
response = requests.post(url, files=files, headers=headers)
response.raise_for_status()
with open(output_image_path, 'wb') as f:
f.write(response.content)
print(f"Image downloaded and saved to {output_image_path}")
except requests.RequestException as e:
print(f"Error: {str(e)}")
return str(e)Step 2: Iterating over a local directory
Step 3: Running the script
Conclusion
Download the code sample
Last updated
Was this helpful?