Skip to content

Instantly share code, notes, and snippets.

@Boldewyn
Created December 12, 2012 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Boldewyn/4269114 to your computer and use it in GitHub Desktop.
Save Boldewyn/4269114 to your computer and use it in GitHub Desktop.
Request a dummy image from http://dummyimage.com from within your shell session. MIT license.
#!/bin/bash
# (C) 2012 Manuel Strehl
#
# Published under the MIT license <http://opensource.org/licenses/mit-license>.
if [ "$1" = "-h" -o "$1" = "--help" ]; then
cat <<USAGE
usage: $(basename $0) WIDTH [HEIGHT]
Request a dummy image from <http://dummyimage.com>. If HEIGHT is omitted, it
is set to WIDTH. You can specify a custom text by piping it to $(basename $0):
$ echo 'Hello World!' | $(basename $0) 500
The image is stored as {WIDTH}x{HEIGHT}.png. You can alter the location by
redirecting the output:
$ $(basename $0) 500 > myname.png
USAGE
exit
fi
w=$1
h=${2-$1}
target="$(pwd)/${w}x${h}.png"
text=
if [ ! -t 0 ]; then
read text
text="$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$text")"
fi
if [ ! -t 1 ]; then
target=-
fi
wget -O "$target" http://dummyimage.com/${w}x${h}/146991/c2dfed.png?text="$text"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment