mirror of
https://github.com/PowerShell/PowerShell.git
synced 2024-11-23 01:34:19 +08:00
Add script to create icns files. (#7456)
Add script to generate macOS icon file. It does not attempt to integrate with the current build process as the macOS icon file is mostly static. `libsvg` was chosen because of its low dependency count over other solutions that use backends like Chromium, PhontomJS, etc. ImageMagick's `convert` was tested but resulting PNGs where not satisfactory and would have required an overcomplicated script having to calculate the `density` argument. * Has a dependency on librsvg (can be installed via Brew) * Uses SVG file as input * Can be integrated in later to build process if desired Closes #7455
This commit is contained in:
parent
725bfdaf88
commit
2a1b6ed9fe
75
tools/generate-icns.sh
Executable file
75
tools/generate-icns.sh
Executable file
@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
lowercase(){
|
||||
echo "$1" | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
|
||||
}
|
||||
|
||||
display_usage() {
|
||||
echo
|
||||
echo " Usage: ./$(basename $0) svgfilename icnsfilename"
|
||||
echo
|
||||
}
|
||||
|
||||
# Verify two arguments are passed.
|
||||
if [ $# != 2 ];then
|
||||
display_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify input SVG exists.
|
||||
if [ ! -f $1 ]; then
|
||||
echo "SVG file not found."
|
||||
display_usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verifiying OS as iconutil is needed."
|
||||
if [ $(lowercase $(uname)) != "darwin" ]; then
|
||||
echo "Unsupported platform. Please run under macOS."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Verify librsvg is installed.
|
||||
if ! hash rsvg-convert 2>/dev/null; then
|
||||
echo "librsvg is not installed."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Create temporary folder for iconset.
|
||||
guid=$(uuidgen)
|
||||
if ! mkdir $guid.iconset >/dev/null 2>&1; then
|
||||
echo "Error creating temporary iconset folder."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Generate images for iconset.
|
||||
rsvg-convert -f png -w 16 -h 16 -o $guid.iconset/icon_16x16.png $1
|
||||
rsvg-convert -f png -w 32 -h 32 -o $guid.iconset/icon_16x16@2x.png $1
|
||||
rsvg-convert -f png -w 32 -h 32 -o $guid.iconset/icon_32x32.png $1
|
||||
rsvg-convert -f png -w 64 -h 64 -o $guid.iconset/icon_32x32@2x.png $1
|
||||
rsvg-convert -f png -w 128 -h 128 -o $guid.iconset/icon_128x128.png $1
|
||||
rsvg-convert -f png -w 256 -h 256 -o $guid.iconset/icon_128x128@2x.png $1
|
||||
rsvg-convert -f png -w 256 -h 256 -o $guid.iconset/icon_256x256.png $1
|
||||
rsvg-convert -f png -w 512 -h 512 -o $guid.iconset/icon_256x256@2x.png $1
|
||||
rsvg-convert -f png -w 512 -h 512 -o $guid.iconset/icon_512x512.png $1
|
||||
rsvg-convert -f png -w 1024 -h 1024 -o $guid.iconset/icon_512x512@2x.png $1
|
||||
|
||||
# Convert iconset to icns.
|
||||
if ! iconutil -c icns $guid.iconset >/dev/null 2>&1; then
|
||||
echo "Error converting iconset to icns."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Remove temporary folder.
|
||||
if ! rm -rf $guid.iconset >/dev/null 2>&1; then
|
||||
echo "Error removing temporary iconset folder."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Rename/Move icns file.
|
||||
if ! mv $guid.icns $2 >/dev/null 2>&1; then
|
||||
echo "Error moving icns file."
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue
Block a user