Skip to content

Instantly share code, notes, and snippets.

@puppybits
Created January 5, 2012 14:18
Show Gist options
  • Select an option

  • Save puppybits/1565441 to your computer and use it in GitHub Desktop.

Select an option

Save puppybits/1565441 to your computer and use it in GitHub Desktop.

Revisions

  1. puppybits revised this gist Jan 26, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion image64.sh
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@ elif [ $xtype == jpeg ] || [ $xtype == jpg ]; then
    elif [ $xtype == png ]; then
    append="data:image/png;base64,";
    elif [ $xtype == svg ]; then
    append="data:svg+xml;base64,";
    append="data:image/svg+xml;base64,";
    elif [ $xtype == ico ]; then
    append="data:image/vnd.microsoft.icon;base64,";
    fi
  2. puppybits revised this gist Jan 5, 2012. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions image64.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,9 @@
    #!/bin/sh
    # Examples:
    # ./image64.sh myImage.png
    # outputs: data:image/png;base64,xxxxx
    # ./image64.sh myImage.png -img
    # outputs: <img src="data:image/png;base64,xxxxx">

    filename=$(basename $1)
    xtype=${filename##*.}
  3. puppybits created this gist Jan 5, 2012.
    29 changes: 29 additions & 0 deletions image64.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/bin/sh

    filename=$(basename $1)
    xtype=${filename##*.}
    append=""
    if [ $xtype == gif ]; then
    append="data:image/gif;base64,";
    elif [ $xtype == jpeg ] || [ $xtype == jpg ]; then
    append="data:image/jpeg;base64,";
    elif [ $xtype == png ]; then
    append="data:image/png;base64,";
    elif [ $xtype == svg ]; then
    append="data:svg+xml;base64,";
    elif [ $xtype == ico ]; then
    append="data:image/vnd.microsoft.icon;base64,";
    fi

    #Mathias Bynens - http://superuser.com/questions/120796/os-x-base64-encode-via-command-line
    data=$(openssl base64 < $1 | tr -d '\n')

    if [ "$#" -eq 2 ] && [ $2 == -img ]; then
    data=\<img\ src\=\"$append$data\"\>
    else
    data=$append$data
    fi

    echo $data | pbcopy

    echo "copied to clipboard"