Obtaining Images for Tiles

The best mosaics come from using a large pool of tile images with a wide variety of colors. Typically, about 300 images is the minimum for good results. And of course, it’s more fun if the pool images are thematically related to the target image: George Washington drawn from presidential portraits, Yoda drawn from frames from Star Wars, etc.

Attribution

The photomosaic package includes convenience functions for downloading image collections from public websites. They use the websites’ official public API to “politely” scrape images and collect attribution information. For each image file, a text file (JSON) with attribution information is also saved. It is possible to filter queries based on their copyright license. If you plan to share or sell your mosaic, pay due attention to the copyright license on the images you download.

At this time, we only support Flickr, but more will be added in the future.

Flickr

Apply for a Flickr API key here. You will get an API key and a secret key. For this application we don’t need the secret key.

import photomosaic as pm
import photomosaic.flickr as pmf

# Provide your API key.
pm.set_options(flickr_api_key='YOUR_API_KEY_HERE')

# Download the first 300 results from a search for 'cats cars'.
pm.from_search('cats cars', 'some_directory', 300)

# Download a specific album.
pmf.from_url('https://www.flickr.com/photos/anapaunkovic/sets/72157646150658189',
             'some_directory')

Download photos matching a search query and the specified license(s).

Parameters
textstring

Search query

deststring

Output directory

cutoffinteger or None, optional

Max number of images to download. By default, None; all matches up to Flickr’s max (4000) will be downloaded.

licenselist or None

List of license codes documented by Flickr at https://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html If None, photomosaic defaults to [1, 2, 4, 5, 7, 8]. See link for details.

photomosaic.flickr.from_url(url, dest)[source]

Download an album (“photoset”) from its url.

The is no programmatic license-checking here; that is up to the user.

Parameters
urlstring

e.g., https://www.flickr.com/photos/<username>/sets/<photoset_id>

deststring

Output directory

Instagram

Instagram’s API requires users to create an app and through a review process to download more than a couple photos. Instaport provides an officially-sanctioned way to download some or all of the photos from any Instagram account, but it is noted to be unreliable. (The first Google suggestion is “instaport not working” and the author’s experience corroborates this.) Alternatively, open https://www.instagram.com/<username>, scroll down until the full history of the account has loaded, and save the page.