Skip to content

Instantly share code, notes, and snippets.

@chunkhang
Last active March 27, 2020 06:10
Show Gist options
  • Save chunkhang/ba5a0004fb8e8efb83b46c77c8ef262d to your computer and use it in GitHub Desktop.
Save chunkhang/ba5a0004fb8e8efb83b46c77c8ef262d to your computer and use it in GitHub Desktop.

Revisions

  1. chunkhang renamed this gist Mar 27, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. chunkhang created this gist Mar 27, 2020.
    18 changes: 18 additions & 0 deletions picsum.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #!/usr/bin/env bash

    function show-help() {
    echo "usage: picsum <width> [height]"
    }

    function download-image() {
    curl --location "https://picsum.photos/${1}/${2}" --output "$3" 2>/dev/null
    echo "$3"
    }

    if [[ "$#" = 0 ]]; then
    show-help
    elif [[ "$#" = 1 ]]; then
    download-image "$1" "$1" "${RANDOM}-${1}-${1}.jpg"
    else
    download-image "$1" "$2" "${RANDOM}-${1}-${2}.jpg"
    fi