Last active
January 2, 2022 15:15
-
-
Save KristobalJunta/a190c6c4055612e1b163f53e291aafb8 to your computer and use it in GitHub Desktop.
A simple script to batch convert images to telegram sticker accepted format, dimensions & file size
This file contains hidden or 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
#!/bin/bash | |
# requiements: | |
# - imagemagick | |
# - pngquant | |
# - npm and renamer package | |
# convert jpg files to png | |
for f in *.jpg; do | |
echo "Processing $f" | |
n="${f%.*}" | |
convert $f "$n.png" | |
done | |
# resize png files to 512x512 | |
for f in *.png; do | |
echo "Processing $f" | |
convert $f -resize 512x512 "$f" | |
done | |
# lossy optimise pngs | |
for f in *.png; do | |
echo "Processing $f" | |
pngquant $f | |
done | |
# clear the directory and move out optimized files only | |
rm *.jpg | |
if [ ! -d "done" ]; then | |
mkdir "done" | |
fi | |
mv *-fs8* "done/" | |
renamer -f "-fs8" "done/*.png" | |
rm *.png | |
echo "All done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Elbobburrito @ottersarecool sorry to hear that.
The intended behavior here is:
I intended it to work such way - it suited my workflow. Maybe there should be a warning before starting the script or smth like that.