Skip to content

Instantly share code, notes, and snippets.

@cuixin
Created January 4, 2019 09:55
Show Gist options
  • Select an option

  • Save cuixin/59a92f7cd16d6760496865cdfd38d02b to your computer and use it in GitHub Desktop.

Select an option

Save cuixin/59a92f7cd16d6760496865cdfd38d02b to your computer and use it in GitHub Desktop.

Revisions

  1. cuixin created this gist Jan 4, 2019.
    25 changes: 25 additions & 0 deletions tinypng.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    #!/bin/bash
    function tinypng() {
    if [[ -z $APK_KEY ]]; then
    echo "API_KEY not defined";
    return 1;
    fi
    if [[ -z $1 ]]; then
    echo "path is empty";
    return 1;
    fi
    body=$(curl https://api.tinify.com/shrink \
    --user api:$API_KEY \
    --data-binary @$1)
    echo $body
    location=$(echo $body | jq '.output.url' | tr -d '"')
    if [[ -z $location ]]; then
    echo "download url is empty";
    return 1;
    fi
    echo $location
    curl $location \
    --user api:$API_KEY \
    --output $1
    }
    tinypng $@