Skip to content

Instantly share code, notes, and snippets.

@dw72
Created November 27, 2016 14:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dw72/24dc5891b35b3a7ed53737272ed10b2d to your computer and use it in GitHub Desktop.
Save dw72/24dc5891b35b3a7ed53737272ed10b2d to your computer and use it in GitHub Desktop.
Generate and install png icons from svg file
#!/usr/bin/bash
src=$1
dst=${1%.*}.png
[[ -z "$2" ]] && type="apps" || type=$2
for i in 16 22 24 32 64 128
do
inkscape -z -e $dst -w $i -h $i $src
xdg-icon-resource install --context $type --size $i $dst
rm $dst
done
@Natetronn
Copy link

In case someone stumbles upon this gist there seems to be a couple changes since this was posted 7 years ago:

The Inkscape flag changes, -e is now -o and -z doesn't appear to exist or be needed any longer.

xgd-icon-resource needed a --novendor flag to process names that didn't meet a particular naming convention, due to a vendor prefix now being required. I updated the prefix in the name, however and skipped the flag.

I converted it to a function and added it to my .zshrc and made a couple changes to suit my needs.

function genicons() {
  src=$1

  [[ -z "$2" ]] && type="apps" || type=$2

  for size in 16 22 24 32 64 128 256 512 1024
  do
    output=${1%.*}-icon_$size.png
    inkscape -o $output -w $size -h $size $src
    xdg-icon-resource install --context $type --size $size $output
    echo "Added icon ~/.local/share/icons/hicolor/${size}x${size}/apps/${output}"
    rm $output
  done
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment