Getting Started
Technical Support
Examples Flexible Cropping Fixed-ratio Cropping Fixed-shape Cropping Command Line Thumbnail Creation Python |
Croppola Documentation – Examples PythonCroppola.com can be accessed using the requests library for Python. The two following scripts may serve as starting point to integrate croppola into your Python project. Note that croppola.com is available free of charge for a volume of up to 100 photos per day, 500 photos per month, or 2400 photos per year. Above that, please request an API key. Cropping a single pictureThe following Python script uploads a picture (tea.jpg) to croppola.com for cropping, and stores the resulting crop: import os, requests # Open the original picture data = open('tea.jpg', 'rb') # Make the request url = 'https://croppola.com/croppola/image.jpg?aspectRatio=1.0&minimumHeight=80%&algorithm=croppola&apiKey=YOURAPIKEY' res = requests.post(url, data=data) # Save the cropped picture if res.status_code == 200: f = open('tea-cropped.jpg', 'wb') f.write(res.content) print('Done!'); else: print('Error ' + str(res.status_code) + '!') To change the aspect ratio, or other parameters, simply modify the URL. Batch cropping all pictures within a folderSimilarly, the following script processes all pictures within the original folder, and stores the crops in the cropped folder: import os, requests, time # Prepare the folders originalFolder = 'original' croppedFolder = 'cropped' if not os.path.exists(croppedFolder): os.makedirs(croppedFolder) # This is the URL url = 'https://croppola.com/croppola/image.jpg?aspectRatio=16:9&maximumHeight=90%&algorithm=croppola&apiKey=YOURAPIKEY' # Process all pictures for pictureFile in os.listdir(originalFolder): print(pictureFile) data = open(originalFolder + '/' + pictureFile, 'rb') res = requests.post(url, data=data, headers={'User-Agent' : 'py'}) data.close(); if res.status_code == 200: f = open(croppedFolder + '/' + pictureFile, 'wb') f.write(res.content) time.sleep(5) # let other people crop else: print('Error ' + str(res.status_code) + '!') break Interactive batch croppingMatthew Gross contributed the following Python script to interactive process a folder: |