PlaybooksCollect Google Images
Build an image catalog filtered by minimum size
Keep only large images and save them to a file (CSV in Python, JSON in the other languages).
Filter out thumbnails and save only high-resolution images.
import csv
import os
import requests
API_KEY = os.environ["AUTOM_API_KEY"]
def get(path, params):
response = requests.get(f"https://api.autom.dev{path}", headers={"x-api-key": API_KEY}, params=params)
if not response.ok:
raise SystemExit(f"Error {response.status_code}: {response.text}")
return response.json()
MIN_WIDTH = 800
def fetch_images(query, pages=2):
results = []
for page in range(1, pages + 1):
data = get("/v1/google/images", {"query": query, "gl": "us", "hl": "en", "page": page})
results.extend(data.get("images", []))
return results
large = [image for image in fetch_images("electric car charging station") if image.get("image_width", 0) >= MIN_WIDTH]
with open("image_catalog.csv", "w", newline="", encoding="utf-8") as file:
fields = ["position", "title", "url", "source", "image_width", "image_height"]
writer = csv.DictWriter(file, fieldnames=fields, extrasaction="ignore")
writer.writeheader()
writer.writerows(large)
print(f"Saved {len(large)} high-res images to image_catalog.csv")The url field in each result is the direct link to the image file. Always verify you have the rights to use an image before including it in a dataset or product.