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!" |
yo this script sucks ass, it deleted all of my memes
@Elbobburrito @ottersarecool sorry to hear that.
The intended behavior here is:
- input is a directory with PNG and/or JPG files.
- the script converts all JPGs to PNGs, then resizes and optimizes (lossy) the PNGs.
- processed PNGs are put to "done" folder and source files are removed
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, I tried using this script, and it created a directory "done" and started changing all the files.....
Then immediately deleted every file in the directory I ran it in, and "done" is empty. Did I do something wrong?