Created
May 13, 2024 03:46
-
-
Save BruceZhang1993/0aada6620014ebe581e1b4d3b7dd3421 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
NC='\033[0m' | |
GREEN='\033[0;32m' | |
BLUE='\033[0;34m' | |
SOURCE_DIR=${1%/} | |
TARGET_DIR="${SOURCE_DIR}_scaled" | |
TARGET_512_DIR="${SOURCE_DIR}_512" | |
if [ -z "$SOURCE_DIR" ]; | |
then | |
echo "Usage: make_telegram_pack [SOURCE_DIR]" | |
exit | |
fi | |
get_image_ratio() { | |
width=$(magick identify -format %w $1) | |
height=$(magick identify -format %h $1) | |
if [ $width -ge $height ]; then | |
echo 1 | |
else | |
echo 0 | |
fi | |
} | |
# Scale original images to 4x | |
echo -e "${BLUE}Upscaling original images to 4x...${NC}" | |
rm -rfv $TARGET_DIR | |
mkdir -pv $TARGET_DIR | |
for file in $SOURCE_DIR/*.png; do | |
source=$file | |
target=$TARGET_DIR/$(basename $file) | |
./tool/realesrgan-ncnn-vulkan -v -s 4 -i $source -o $target -n realesrgan-x4plus | |
done | |
# scale images to telegram 512px | |
echo -e "${BLUE}Downscaling 4x images to Telegram 512px...${NC}" | |
rm -rfv $TARGET_512_DIR | |
mkdir -pv $TARGET_512_DIR | |
for file in $TARGET_DIR/*.png; do | |
source=$file | |
target=$TARGET_512_DIR/$(basename $file) | |
r=$(get_image_ratio $file) | |
if [ $r -gt "0" ]; then | |
magick convert $source -verbose -resize 512x $target | |
else | |
magick convert $source -verbose -resize x512 $target | |
fi | |
done | |
echo -e "${GREEN}ALL DONE! Sticker pack saved at ${TARGET_512_DIR} .${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment