Skip to content

Instantly share code, notes, and snippets.

@troutcolor
Created December 20, 2022 20:01
Show Gist options
  • Save troutcolor/370a49898124413c78d17a5c86c42a2e to your computer and use it in GitHub Desktop.
Save troutcolor/370a49898124413c78d17a5c86c42a2e to your computer and use it in GitHub Desktop.
#script to download pile of flickr images and make a montage #needs montage command which comes with imagemagick I install that with homebrew #some notes at the end of the file
#!/bin/bash
#script to download pile of flickr images and make a montage
#needs montage command which comes with imagemagick I install that with homebrew
#some notes at the end of the file
#Fill in the params any except the APIKEY can be empty
# this will take some time!
APIKEY='FILL-IN_API_KEY'
#this is my flickr user id you probably want to change that.
USERID='71428177%40N00'
SINCEDATE='2022-01-01'
#unix timestamp or mysql datetime
TAGS=''
NUMPHOTOS='500'
#max photos 500
#Need to know how many pages there are if you want more that the first 500 images
PAGES='1'
PHOTOSORT='date-taken-desc'
#date-posted-desc
#date-posted-asc
#date-posted-desc
#date-taken-asc
#date-taken-desc
#interestingness-desc
#interestingness-asc
#relevance
#### END OF SETTINGS ####
#Make a temp directory to work in
TEMPDIR=$(mktemp -d -t 'mytmpdir')
open $TEMPDIR
HERE=$( pwd )
trap "{ cd $HERE ; rm -rf $TEMPDIR; exit 255; }" SIGINT
cd $TEMPDIR
ALLFILELIST=""
for counter in `seq 1 $PAGES`;
do
searchurl="https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=${APIKEY}&user_id=${USERID}&media=photos&min_taken_date=${SINCEDATE}&text=${TAGS}&extras=url_q&sort=${PHOTOSORT}&per_page=${NUMPHOTOS}&page=${counter}&format=rest"
#url_q is small square
FILELIST=$(curl "$searchurl" | sed -ne 's/.*\(http[^"]*\).*/\1/p')
ALLFILELIST="$ALLFILELIST $FILELIST"
done
echo $ALLFILELIST
a=`echo $ALLFILELIST | wc -w`
for i in $ALLFILELIST ;
do
let a=a-1
new=$(printf "%04d.jpg" "$a")
curl -o $new $i
done;
/usr/local/bin/montage *.jpg montage.jpeg
##this seems to give a squarish image, so I often cd into the directory and us:
#montage -mode concatenate -tile 30x *.jpg montage.jpeg
# to make a landscape montage You can also use -background black
#I use .jpeg for the output so I don't get a montage mixed in to the next montage'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment