Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • 77-improve-app-metadata
  • 68-add-words
  • 62-fix-get-image-when-word-with-accent
  • 44-implement-game-write-word-from-letters
  • 43-add-script-to-get-images-from-assets
  • 32-add-accents-and-diacritics-in-french-words-2
  • Release_0.10.0_80 protected
  • Release_0.9.2_79 protected
  • Release_0.9.1_78 protected
  • Release_0.9.0_77 protected
  • Release_0.8.0_76 protected
  • Release_0.7.0_75 protected
  • Release_0.6.0_74 protected
  • Release_0.5.2_73 protected
  • Release_0.5.1_72 protected
  • Release_0.5.0_71 protected
  • Release_0.4.1_70 protected
  • Release_0.4.0_69 protected
  • Release_0.3.1_68 protected
  • Release_0.3.0_67 protected
  • Release_0.2.1_66 protected
  • Release_0.2.0_65 protected
  • Release_0.1.40_64 protected
  • Release_0.1.39_63 protected
  • Release_0.1.38_62 protected
  • Release_0.1.37_61 protected
27 results

build_images.sh

Blame
  • build_images.sh 1.79 KiB
    #! /bin/bash
    
    # Check dependencies
    command -v inkscape >/dev/null 2>&1 || { echo >&2 "I require inkscape but it's not installed. Aborting."; exit 1; }
    command -v scour >/dev/null 2>&1 || { echo >&2 "I require scour but it's not installed. Aborting."; exit 1; }
    command -v optipng >/dev/null 2>&1 || { echo >&2 "I require optipng but it's not installed. Aborting."; exit 1; }
    command -v convert >/dev/null 2>&1 || { echo >&2 "I require convert (imagemagick) but it's not installed. Aborting."; exit 1; }
    
    CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
    BASE_DIR="$(dirname "${CURRENT_DIR}")"
    
    CONVERT_OPTIONS="-alpha off +dither -colors 256 -depth 4"
    OPTIPNG_OPTIONS="-preserve -quiet -o7"
    
    # optimize svg
    function optimize_svg() {
      SOURCE="$1"
    
      cp ${SOURCE} ${SOURCE}.tmp
      scour \
          --remove-descriptive-elements \
          --enable-id-stripping \
          --enable-viewboxing \
          --enable-comment-stripping \
          --nindent=4 \
          -i ${SOURCE}.tmp \
          -o ${SOURCE}
      rm ${SOURCE}.tmp
    }
    
    # build image
    function build_image() {
      SOURCE="$1"
      TARGET_PNG="$2"
      IMAGE_WIDTH="$3"
      IMAGE_HEIGHT="$4"
    
      inkscape \
          --export-width=${IMAGE_WIDTH} \
          --export-height=${IMAGE_HEIGHT} \
          --export-filename=${TARGET_PNG} \
          ${SOURCE}
    }
    
    # optimize image
    function optimize_image() {
      IMAGE_FILE="$1"
    
      convert "${IMAGE_FILE}" ${CONVERT_OPTIONS} "${IMAGE_FILE}"
      optipng ${OPTIPNG_OPTIONS} ${IMAGE_FILE}
    }
    
    # build menu image
    function build_menu_image() {
      IMAGE_NAME="$1"
    
      INPUT_SVG="${CURRENT_DIR}/menu/${IMAGE_NAME}.svg"
      OUTPUT_PNG="${BASE_DIR}/assets/menu/${IMAGE_NAME}.png"
    
      optimize_svg "${INPUT_SVG}"
      build_image "${INPUT_SVG}" "${OUTPUT_PNG}" 640 640
      optimize_image "${OUTPUT_PNG}"
    }
    
    
    build_menu_image "game-pick-image"
    build_menu_image "game-pick-word"