From 8c6b3da0abae1102e434e1c2567c97a85515bbcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C4=83t=C4=83lin=20Mari=C8=99?= Date: Sat, 20 Jul 2013 18:58:28 +0300 Subject: [PATCH] Update image generator script Make script generate different sized versions of the original logos ('16x16', '24x24', '32x32', '48x48', '64x64', '128x128', '256x256' and '512x512'). --- scripts/generate-image.sh | 57 ----------------- scripts/generate-images.sh | 127 +++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+), 57 deletions(-) delete mode 100755 scripts/generate-image.sh create mode 100755 scripts/generate-images.sh diff --git a/scripts/generate-image.sh b/scripts/generate-image.sh deleted file mode 100755 index 57ba7609a5..0000000000 --- a/scripts/generate-image.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env bash - -# This script automatically generates the `all-desktop.png` image, but in -# order for it to work, you will need to have `ImageMagick Command-Line -# Tools` installed: http://www.imagemagick.org/script/command-line-tools.php. - -generate_img() { - - local outputImgName="" - - if [ $(is_installed "convert") -eq 1 ]; then - - outputImgName="$1" - shift - - # `convert` command options: - # http://www.imagemagick.org/script/convert.php#options - - convert $@ \ - -background transparent \ - -gravity center \ - -resize 512x512 \ - -extent 562x562 \ - +append \ - $outputImgName \ - && print_success_msg "Done! 🍻 " - - else - print_error_msg "Please install ImageMagick Command-Line Tools!" - fi - -} - -is_installed() { - - # 0 = not installed - # 1 = installed - - printf "$( [[ -x "$(command -v "$1")" ]] && printf "1" || printf "0" )" -} - -print_error_msg() { - print_msg "$1" -} - -print_msg() { - printf "\n %s\n\n" "$1" -} - -print_success_msg() { - print_msg "$1" -} - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -generate_img "all-desktop.png" \ - "chrome.png" "firefox.png" "ie9-10.png" "opera.png" "safari.png" diff --git a/scripts/generate-images.sh b/scripts/generate-images.sh new file mode 100755 index 0000000000..9132983653 --- /dev/null +++ b/scripts/generate-images.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash + +# This script automatically generates the `all-desktop.png` image as well as +# all the different sized versions of the logos. In order for it to work, you +# will need to have `ImageMagick Command-Line Tools` installed. +# http://www.imagemagick.org/script/command-line-tools.php. + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +declare groupImgName="all-desktop.png" + +declare -a imgGroup=( + "../chrome/chrome.png" + "../firefox/firefox.png" + "../ie9-10/ie9-10.png" + "../opera/opera.png" + "../safari/safari.png" +) + +declare -a imgSizes=( + '16x16' + '24x24' + '32x32' + '48x48' + '64x64' + '128x128' + '256x256' + '512x512' +) + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +generate_group_img() { + + # `convert` command options: + # http://www.imagemagick.org/script/convert.php#options + + convert "${imgGroup[@]}" \ + -background transparent \ + -gravity center \ + -resize 512x512 \ + -extent 562x562 \ + +append \ + "../$groupImgName" \ + && print_success_msg " [create]" "../$groupImgName" +} + +generate_imgs() { + + while read i; do + + # remove outdated images + rm ../$i/${i}_* &> /dev/null + + # generate the different sized versions of an image + for s in ${imgSizes[@]}; do + convert "../$i/$i.png" \ + -background transparent \ + -gravity center \ + -resize "$s" \ + "../$i/${i}_$s.png" \ + && print_success_msg " [create]" "../$i/${i}_$s.png" + done + + done < <(ls -l ../ | grep '^d' | grep -v "scripts" | cut -d":" -f2 | cut -d' ' -f2-) + # └─ images directories + +} + +is_installed() { + + # 0 = not installed + # 1 = installed + + printf "$( [[ -x "$(command -v "$1")" ]] && printf "1" || printf "0" )" + +} + +print_error_msg() { + print_msg "$1" +} + +print_msg() { + printf " %s\n" "$1" +} + +print_success_msg() { + print_msg "$1 $2" +} + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +main() { + + if [ $(is_installed "convert") -eq 1 ]; then + + print_msg "" + print_success_msg "Generate images" + print_msg "" + + generate_group_img \ + && generate_imgs \ + && ( + print_msg "" + print_success_msg "Done! 🍻 " + print_msg "" + ) + + # Optional: start ImageOptim + # https://github.com/JamieMason/ImageOptim-CLI + if (( "$(uname -s)" == "Darwin" + && ( $(is_installed "imageOptim") == 1 ) )); then + + print_msg "" + print_success_msg "Optimize images (this may take some time)" + print_msg "" + + imageOptim --directory ../ + fi + + else + print_error_msg "Please install ImageMagick Command-Line Tools!" + fi + +} + +main