mirror of
https://github.com/scratchfoundation/scratch-link.git
synced 2024-11-14 19:05:03 -05:00
perf(Win): shrink tray icon, speed up svg-convert.sh
This commit is contained in:
parent
e79252f2dd
commit
adeaf1da6b
3 changed files with 9 additions and 6 deletions
2
Makefile
2
Makefile
|
@ -125,7 +125,7 @@ $(eval $(call svg2png,Scratch\ Link\ Safari\ Helper/Scratch\ Link\ Safari\ Exten
|
|||
# https://stackoverflow.com/q/3236115
|
||||
# https://iconhandbook.co.uk/reference/chart/windows/
|
||||
$(eval $(call svg2ico,scratch-link-win/scratch-link.ico,Assets/square.svg,256 128 96 64 48 32 24 16))
|
||||
$(eval $(call svg2ico,scratch-link-win/scratch-link-tray.ico,Assets/simplified.svg,256 128 96 64 48 32 24 16))
|
||||
$(eval $(call svg2ico,scratch-link-win/scratch-link-tray.ico,Assets/simplified.svg,32 24 16))
|
||||
|
||||
# Windows MSIX
|
||||
# TODO: does Microsoft really want DPI=72 for all of these?
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 139 KiB After Width: | Height: | Size: 5.3 KiB |
|
@ -26,8 +26,10 @@ set -e
|
|||
INPUT_SVG="$1"
|
||||
shift 1
|
||||
|
||||
# DISPLAY="" prevents 'convert' from trying to contact an X server, which can slow it down quite a bit.
|
||||
# This might cause problems if the SVG contains text but does not embed the necessary font(s).
|
||||
echo "Detecting border color..."
|
||||
BORDER_COLOR=$(convert -background none -format '%[pixel:u.p{1,1}]' "${INPUT_SVG}" info:)
|
||||
BORDER_COLOR=$(DISPLAY="" convert -background none -format '%[pixel:u.p{1,1}]' "${INPUT_SVG}" info:)
|
||||
echo "Detected border color: ${BORDER_COLOR}"
|
||||
|
||||
# Usage: svg2png output.png width height DPI
|
||||
|
@ -38,24 +40,25 @@ svg2png () {
|
|||
PNG_DPI="$4"
|
||||
set -x
|
||||
cairosvg --output-height "${PNG_HEIGHT}" -f png -o - "${INPUT_SVG}" |
|
||||
convert -background "${BORDER_COLOR}" -gravity center -extent "${PNG_WIDTH}x${PNG_HEIGHT}" -density "${PNG_DPI}" - "${OUTPUT_PNG}"
|
||||
DISPLAY="" convert -background "${BORDER_COLOR}" -gravity center -extent "${PNG_WIDTH}x${PNG_HEIGHT}" -density "${PNG_DPI}" - "${OUTPUT_PNG}"
|
||||
optipng -o7 -zm1-9 "$OUTPUT_PNG"
|
||||
}
|
||||
|
||||
# Usage: svg2ico output.ico sizes...
|
||||
svg2ico () {
|
||||
set -e
|
||||
OUTPUT_ICO="$1"
|
||||
shift
|
||||
SVG2ICO_TMP=$(mktemp -d -t svg2ico-XXXXXXXXXX)
|
||||
trap 'echo "Cleaning up..." >&2; rm -rv "${SVG2ICO_TMP}"; exit' EXIT HUP INT TERM
|
||||
ICO_PNGS=()
|
||||
ICO_IMAGES=()
|
||||
for SIZE in "$@"; do
|
||||
ICO_PNG="${SVG2ICO_TMP}/icon-${SIZE}.png"
|
||||
ICO_PNGS+=("${ICO_PNG}")
|
||||
ICO_IMAGES+=("${ICO_PNG}")
|
||||
svg2png "${ICO_PNG}" "${SIZE}" "${SIZE}" 96 &
|
||||
done
|
||||
wait # for all PNGs to be created and optimized
|
||||
(set -x && convert "${ICO_PNGS[@]}" "${OUTPUT_ICO}")
|
||||
(set -x && DISPLAY="" convert "${ICO_IMAGES[@]}" "${OUTPUT_ICO}")
|
||||
}
|
||||
|
||||
# $1 = output file
|
||||
|
|
Loading…
Reference in a new issue