Search for image using Google Custom Search API and resize & crop the image afterwords
Project description
Google Images Search
Ok, here's the thing, you want to fetch one image from Google Images and
you want to resize it and crop it from the middle
This code enables you to do that.
Before you continue you need to setup your Google developers account and project:
https://console.developers.google.com
(Among all of the Google APIs enable "Custom Search API" for your project)
https://cse.google.com/cse/all
(In the web form where you create/edit your custom search engine enable "Image search" option and and for "Sites to search" option select "Search the entire web but emphasize included sites")
After setting up you Google developers account and project you should have your developers API key and project CX
CLI usage
# without environment variables:
> gimages -k __your_dev_api_key__ -c __your_project_cx__ search -q puppies
# with environment variables:
> export GCS_DEVELOPER_KEY=__your_dev_api_key__
> export GCS_CX=__your_project_cx__
>
> gimages search -q puppies
# search only (no download and resize):
> gimages search -q puppies
# search and download only (no resize):
> gimages search -q puppies -d /path/on/your/drive/where/images/should/be/downloaded
# search, download and resize:
> gimages search -q puppies -d /path/ -w 500 -h 500
Programmatic usage
from google_images_search import GoogleImagesSearch
# if you don't enter api key and cx, the package will try to search
# them from environment variables GCS_DEVELOPER_KEY and GCS_CX
gis = GoogleImagesSearch('__your_dev_api_key__', '__your_project_cx__')
#define search params:
search_params = {
'q': '...',
'num': 1-50,
'safe': 'high|medium|off',
'fileType': 'jpg|gif|png',
'imgType': 'clipart|face|lineart|news|photo',
'imgSize': 'huge|icon|large|medium|small|xlarge|xxlarge',
'searchType': 'image',
'imgDominantColor': 'black|blue|brown|gray|green|pink|purple|teal|white|yellow'
}
# this will only search for images:
gis.search(search_params=search_params)
# this will search and download:
gis.search(search_params=search_params, path_to_dir='/path/')
# this will search, download and resize:
gis.search(search_params=search_params, path_to_dir='/path/', width=500, height=500)
# search first, then download and resize afterwords
gis.search(search_params=search_params)
for image in gis.result():
image.download('/path/')
image.resize(500, 500)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Google Images Search-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9661f8923c5f019a0fb44ebb1761eec8b8830e05df02754b341faed312fd3c4d |
|
MD5 | d1a74ac8a5b9fe408aa5323ff9991451 |
|
BLAKE2b-256 | 94ef75d7bfbf14fdc180346a5a025534b7f179ab3a4b7273cae03b2853680116 |
Hashes for Google_Images_Search-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c96de1daa316209d9fec6ee69041816c1bce6c3f422b6a48dd67636a8bbd8a1 |
|
MD5 | 6537250330b8bca58de9c188dc573f95 |
|
BLAKE2b-256 | b5183f2dbb93601549683c6a9c3eae2322b2874ee8cbd43a1d3ad6f0fd169cc8 |