Skip to content

Instantly share code, notes, and snippets.

@dgdavid
Last active July 5, 2017 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgdavid/4d9cda407a35f49319641c436a6e44dd to your computer and use it in GitHub Desktop.
Save dgdavid/4d9cda407a35f49319641c436a6e44dd to your computer and use it in GitHub Desktop.
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
Copy link
Author

dgdavid 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