Created
December 12, 2012 16:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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