This is a command line python program to search keywords/key-phrases on Google Images
and optionally download images to your computer. You can also invoke this script from
another python file.

This is a small and ready-to-run program. No dependencies are required to be installed
if you would only want to download up to 100 images per keyword. If you would want more than 100
images per keyword, then you would need to install Selenium library along with chromedriver.
Detailed instructions in the troubleshooting section.

This program is compatible with both the versions of python - 2.x and 3.x (recommended).
It is a download-and-run program with no changes to the file.
You will just have to specify parameters through the command line.

Denotes the keywords/key phrases you want to search for. For more than one keywords, wrap it in single quotes.

Tips:

If you simply type the keyword, Google will best try to match it

If you want to search for exact phrase, you can wrap the keywords in double quotes ("")

If you want to search to contain either of the words provided, use OR between the words.

If you want to explicitly not want a specific word use a minus sign before the word (-)

keywords_from_file

kf

Denotes the file name from where you would want to import the keywords.

Add one keyword per line. Blank/Empty lines are truncated automatically.

Only file types '.txt' or '.csv' are allowed.

prefix_keywords

pk

Denotes additional words added before main keyword while making the search query.

The final search query would be: <prefix keyword> <keyword>

So, for example, if the keyword is 'car' and prefix_keyword is 'red,yellow,blue', it will search and download images for
'red car', 'yellow car' and 'blue car' individually

suffix_keywords

sk

Denotes additional words added after main keyword while making the search query.

The final search query would be: <keyword> <suffix keyword>

So, for example, if the keyword is 'car' and suffix_keyword is 'red,yellow,blue', it will search and download images for
'car red', 'car yellow' and 'car blue' individually

limit

l

Denotes number of images that you want to download.

You can specify any integer value here. It will try and get all the images that it finds in the google image search page.

If this value is not specified, it defaults to 100.

Note: In case of occasional errors while downloading images, you could get less than 100 (if the limit is set to 100)

related_images

ri

This argument downloads a ton of images related to the keyword you provided.

Google Images page returns list of related keywords to the keyword you have mentioned in the query. This tool downloads
images from each of those related keywords based on the limit you have mentioned in your query

This argument does not take any value. Just add '--related_images' or '-ri' in your query.

Note: This argument can download hundreds or thousands of additional images so please use this carefully.

This value of this argument can be specified as <integer,integer> where the fist integer stands for width of the image
and the second integer stands for the height of the image. For example, -es 1024,786

Note: You cannot specify both 'size' and 'exact_size' arguments in the same query. You can only give one of them.

aspect_ratio

a

Denotes the aspect ratio of images to download.

Possible values: tall, square, wide, panoramic

type

t

Denotes the type of image to be downloaded.

Possible values: face, photo, clip-art, line-drawing, animated

time

w

Denotes the time the image was uploaded/indexed.

Possible values: past-24-hours, past-7-days

time_range

wr

Denotes the time range for which you want to search the images

The value of this parameter should be in the following format '{"time_min":"MM/DD/YYYY","time_max":"MM/DD/YYYY"}'

delay

d

Time to wait between downloading two images

Time is to be specified in seconds. But you can have sub-second times by using decimal points.

url

u

Allows you search by image when you have the URL from the Google Images page.
It downloads images from the google images link provided

If you are searching an image on the browser google images page, simply grab the browser URL and paste it in this parameter
It will download all the images seen on that page.

single_image

x

Allows you to download one image if the complete (absolute) URL of the image is provided

output_directory

o

Allows you specify the main directory name in which the images are downloaded.

If not specified, it will default to 'downloads' directory. This directory is located in the path from where you run this code

together they make: /Library/Frameworks/Python.framework/Versions/2.7/bin which you need add it to the path:

$ export PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin"

#~~~# [Errno 13] Permission denied creating directory 'downloads'

When you run the command, it downloads the images in the current directory (the directory from where you are running the command). If you get permission denied error for creating the downloads directory, then move to a directory in which you have the write permission and then run the command again.

#~~~# Permission denied while installing the library

On MAC and Linux, when you get permission denied when installing the library using pip, try doing a user install.

$ pip install google_images_download --user

You can also run pip install as a superuser with sudo pip install google_images_download but it is not generally a good idea because it can cause issues with your system-level packages.

#~~~# Installing the chromedriver (with Selenium)

If you would want to download more than 100 images per keyword, then you will need to install 'selenium' library along with 'chromedriver' extension.

If you have pip-installed the library or had run the setup.py file, Selenium would have automatically installed on your machine. You will also need Chrome browser on your machine. For chromedriver:

This program lets you download tons of images from Google.
Please do not download or use any image that violates its copyright terms.
Google Images is a search engine that merely indexes images and allows you to find them.
It does NOT produce its own images and, as such, it doesn't own copyright on any of them.
The original creators of the images own the copyrights.

Images published in the United States are automatically copyrighted by their owners,
even if they do not explicitly carry a copyright warning.
You may not reproduce copyright images without their owner's permission,
except in "fair use" cases,
or you could risk running into lawyer's warnings, cease-and-desist letters, and copyright suits.
Please be very careful before its usage!