Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WIP - normalize svg icons script
#!/bin/bash
size="$1"
NC='\033[0m' # No Color
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
VALID_ICON='\xE2\x9C\x93'
NOT_VALID_ICON='\xE2\x9C\x97'
ARROW_ICON='\xE2\x86\x92'
WARNING_ICON='\xE2\x9A\xA0'
SQUARE_ICON='\xE2\x96\xAA'
function log_info {
echo -e "${BLUE}${SQUARE_ICON} $1${NC}"
}
function log_error {
echo -e "${RED}${NOT_VALID_ICON} $1${NC}"
}
function log_success {
echo -e "${GREEN}${VALID_ICON} $1${NC}"
}
function log_warning {
echo -e "${YELLOW}${WARNING_ICON} $1${NC}"
}
function log_message {
echo -e " ${ARROW_ICON} $1"
}
echo ''
echo 'normalize-svg-icons'
echo '-------------------'
echo ''
echo ''
echo 'Checking system...'
echo ''
which rsvg-convert > /dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
log_error 'rsvg-convert not installed.'
exit 1
else
log_success 'rsvg-convert installed.'
fi
which svgcleaner > /dev/null 2>&1
if [[ ! $? -eq 0 ]]; then
log_error 'svgleaner not installed.'
log_message 'Please, visit the page project at https://github.com/RazrFalcon/svgcleaner and install it.'
exit 1
else
log_success 'svgleaner installed.'
fi
echo ''
echo 'Checking arguments...'
echo ''
if [[ -z "$size" ]]; then
echo ""
log_warning 'PLEASE, SPECIFY A SIZE.'
echo ""
exit 1
fi
rm -rf "$size"
mkdir -p "$size"
echo ''
echo 'Starting normalization...'
echo ''
COUNTER=0
start_time="$(date +%s)"
find . -maxdepth 1 -type f -name "*.svg" -print0 | while IFS= read -r -d '' file; do
if [[ ! -h "$file" ]]; then
log_info "$file found..."
rsvg-convert "$file" -h "$size" -a -f svg -o "$size/$file"
log_success "resized."
svgcleaner "$size/$file" "$size/$file" &> /dev/null
log_success "cleaned."
let COUNTER++
fi
done
end_time="$(date +%s)"
echo ''
echo '-------------------'
echo ''
log_message "$COUNTER file(s) processed in $(($end_time - $start_time)) second(s)."
@dgdavid

This comment has been minimized.

Copy link
Owner Author

commented Jun 30, 2017

Based on svgscale Numix tool, the idea is to change the height of a bunch icons keeping the aspect ratio and (not yet done) clean up the files using svgcleaner before use them in Fontello to build a custom icon font.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.