Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get three placeholder images of set sizes, with random filenames
#!/bin/sh
# Set a few variables
SIZE_M=(750 422)
SIZE_T=(1536 864)
SIZE_D=(2780 1564)
BASE="https://picsum.photos"
# Move to the download folder
cd ~/Downloads
# Get the first image, to see what the redirect is (so all images match)
IMG_URL=$(curl -Ls -o /dev/null -w %{url_effective} "https://picsum.photos/${SIZE_M[0]}/${SIZE_M[1]}")
ENDPARAMS=${IMG_URL##*/id/}
IMG_ID=${ENDPARAMS%%/*}
BASE="${BASE}/id/${IMG_ID}"
MOBILE="${BASE}/${SIZE_M[0]}/${SIZE_M[1]}"
TABLET="${BASE}/${SIZE_T[0]}/${SIZE_T[1]}"
DESKTOP="${BASE}/${SIZE_D[0]}/${SIZE_D[1]}"
# Fetch each of the files
PREFIX=$(cat /dev/urandom | env LC_CTYPE=C tr -dc 'a-z0-9' | fold -w 8 | head -n 1)
printf "." && wget -q -O "${PREFIX}_${SIZE_D[0]}x${SIZE_D[1]}.jpg" "$DESKTOP"
sleep 0.2
printf "." && wget -q -O "${PREFIX}_${SIZE_T[0]}x${SIZE_T[1]}.jpg" "$TABLET"
sleep 0.2
printf "." && wget -q -O "${PREFIX}_${SIZE_M[0]}x${SIZE_M[1]}.jpg" "$MOBILE"
echo "done!"
ls -lsa ~/Downloads | grep -o -e "${PREFIX}.*" --color=none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment