image magick
Setup graphicsmagick
Mac users, first download and install GraphicsMagick. In Mac OS X, you can simply use Homebrew
brew install graphicsmagickWindows users, you can download the installer from http://www.graphicsmagick.org/download.html
GraphicsMagick-X.X.XX-Q8-win32-dll.exe should work for you.
rename_image.sh x.png
#!/bin/bash
# Function to check if a program is installed
function is_installed() {
command -v "$1" >/dev/null 2>&1
}
# Check if imagemagick is installed
if ! is_installed "convert"; then
echo "Error: ImageMagick is not installed. Please install it using your package manager."
exit 1
fi
# Get the filename without extension
filename="${1%.*}"
# Check if a filename was provided
if [ -z "$filename" ]; then
echo "Error: Please provide a filename as an argument."
exit 1
fi
# Rename to x@4x.png
mv "$1" "$filename@4x.png"
# Resize to 50% and rename to x@2x.png
convert -resize 50% "$filename@4x.png" "$filename@2x.png"
# Resize to 25% and rename to x.png
convert -resize 25% "$filename@2x.png" "$filename.png"
echo "Successfully renamed and resized the image."create a mask
https://blog.kyubuns.dev/entry/2022/12/07/185311
background=$(convert input.png -format %c histogram:info:- | sort -rn | head -n 1 | xargs echo | cut -f 2 -d' ')
convert input.png -fuzz 10% -transparent rgb$background tmp1.png
convert tmp1.png -fill 'rgb(255,255,255)' -colorize 100 -background 'rgb(0,0,0)' -alpha remove output.pngexec_magic.command
OUTPUT="{{filename}}"
PROJPATH="{{path}}"
SANDPATH="{{tmp}}"
BINPATH="{{bin}}"
LOOP={{loop}}
DELAY=50
# 25= 4 fps
export MAGICK_HOME="$BINPATH"
export PATH="$MAGICK_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"
chmod u+x "$MAGICK_HOME/bin/convert"
convert -loop $LOOP -delay $DELAY "$SANDPATH"/capture_*.png $PROJPATH/"$OUTPUT".gif