Examples¶
Documentation Homepage | GitHub Repository | Input Arguments
Config File Format¶
You can either pass the arguments directly from the command line or through a config file. Below is a sample of how a config file looks.
You can pass more than one record through a config file. The code will iterate through each record and download images based on the arguments passed.
{
"Records": [
{
"keywords": "apple",
"limit": 5,
"color": "green",
"print_urls": true
},
{
"keywords": "universe",
"limit": 15,
"size": "large",
"print_urls": true
}
]
}
Code Example - Importing the Library¶
If you are calling this library from another Python file:
from google_images_download import google_images_download # importing the library
response = google_images_download.googleimagesdownload() # class instantiation
arguments = {
"keywords": "Polar bears,baloons,Beaches",
"limit": 20,
"print_urls": True
}
paths = response.download(arguments) # passing the arguments to the function
print(paths) # printing absolute paths of the downloaded images
Command Line Examples¶
Using a config file¶
If you are passing arguments from a config file, simply pass the config_file argument with the name of your JSON file:
Simple keyword search with limit¶
Using shorthand arguments¶
Using Suffix Keywords¶
Suffix Keywords allow you to specify words after the main keywords. For example, if keyword = car and suffix keyword = 'red,blue', it will first search for car red and then car blue:
Download images with specific format¶
Using color filters¶
Non-English keywords¶
Download from a Google Images URL¶
Save to specific directory¶
Instead of saving to 'downloads', save to a custom directory:
Download a single image by URL¶
Size and type constraints¶
Specific usage rights¶
Specific color type¶
Specific aspect ratio¶
Reverse Image Search¶
Download images similar to the image URL provided:
Download from specific website¶
Using chromedriver path (if needed)¶
If the automatic chromedriver management fails, you can specify the path manually:
On Windows:
Print URLs without downloading¶
Extract metadata to JSON¶
This creates a JSON file in the logs/ directory with metadata for all downloaded images.
Download with delay¶
Add a delay between downloads to avoid rate limiting:
Related images¶
Download images from related keywords (can download hundreds of additional images):
Note: The images are downloaded in their own sub-directories inside the main directory (either the one you provided with -o or in 'downloads') in the same folder you are in.
Library Extensions¶
Cleaning Corrupt Images¶
The downloading algorithm does a good job of keeping out corrupt images, but it's not perfect. Below script will help clean corrupt image files. This script was ideated by @devajith in Issue 81: