Created
June 26, 2018 02:26
-
-
Save jcamilom/ebdbf9b2bc2e00c2281e44313184ab3e to your computer and use it in GitHub Desktop.
[Create icons] How to create different sized icons for apps in Linux #linux #bash
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 | |
# This will create icons in their respective | |
# folders in "$HOME"/.local/share/icons/... | |
# Usage: icongen iconfile | |
# Check usage | |
if [[ $# -ne 2 ]]; then | |
echo "Usage: $0 icon_file new_icon_name" | |
exit 1 | |
fi | |
# Check if the icon file provided in the first | |
# argument actually exists | |
if [ ! -f $1 ]; then | |
echo error: file $1 does not exist | |
exit 1 | |
fi | |
# Get the icon info, so the dimension can be extracted | |
icon_info=$(file $1) | |
# regex to extract the dim in the format "300 x 300" | |
dim_regex='[0-9]+[[:space:]]x[[:space:]][0-9]+' | |
# Get the icon dimmension | |
if [[ $icon_info =~ $dim_regex ]]; then | |
dim="${BASH_REMATCH[0]}" | |
echo Icon size: $dim | |
# Extract the first number, e.g. "300" from "300 x 300" | |
if [[ $dim =~ ^[0-9]+ ]]; then | |
dim1=${BASH_REMATCH[0]} | |
# Array with the icon sizes to be genrated | |
icon_sizes=(16 24 32 48 64 96 128 256 512) | |
for icon_size in ${icon_sizes[*]} | |
do | |
# Check if the current dimension is smaller or equal | |
# than the original icon | |
if [[ "$dim1" -ge "$icon_size" ]]; then | |
# resize the icon to the current icon_size creating a new file | |
convert -resize "$icon_size"x"$icon_size" $1 $2 | |
# move it to the proper folder | |
dest="$HOME"/.local/share/icons/hicolor/"$icon_size"x"$icon_size"/apps | |
mv -i $2 $dest | |
# Check if the last command succeeded | |
if [ $? -eq 0 ]; then | |
# Success | |
echo "$icon_size"x"$icon_size" icon created at $dest created | |
else | |
# Failure | |
echo failed to create "$icon_size"x"$icon_size" icon | |
fi | |
fi | |
done | |
fi | |
else | |
echo error: "icon's dimmension couldn't be extracted" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment