Skip to content

Instantly share code, notes, and snippets.

@thisbit
Created December 7, 2021 13:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thisbit/55d919aa773d75e8981465aafe98bf9e to your computer and use it in GitHub Desktop.
Save thisbit/55d919aa773d75e8981465aafe98bf9e to your computer and use it in GitHub Desktop.
A simple script for image optimization using FFMPEG (read the comment)
#!/bin/bash
echo "WARNING: run this in the folder that contains images"
read -p "# IMAGE FILETYPE (type number):
(1) jpg
(2) png
(3) tif
(4) all (WARN: works only on raster images)
: " format
if [[ $format = "1" ]]
then
filetype="JPG"
imagequery="*.[jJ][pP]*[gG]"
elif [ $format = "2" ]
then
filetype="PNG"
imagequery="*.[pP][nN][gG]"
elif [ $format = "3" ]
then
filetype="TIFF"
imagequery="*.[tT][iI][fF]*"
elif [ $format = "4" ]
then
filetype="ALL IMGS IN FOLDER"
imagequery="*"
else
echo "ERROR, unknown image type"
exit
fi
echo "Got it, it's - $filetype !"
read -p "# IMAGE WIDTH (type px numbers only): " width
read -p "# IMAGE DESTINATION FOLDER (type folder name): " output
mkdir ./"$output"; for f in $imagequery; do ffmpeg -i "$f" -vf scale="$width":-1 "./$output/${f%%}"; done
@thisbit
Copy link
Author

thisbit commented Dec 7, 2021

Image Resize

Script adds a simple productivity feature to your workflow if you find yourself having to resize multiple files often. Best used if you add a symlink to your machine so it can be ran from any folder.

sudo ln -s /path/to/where/the/script/is/located symlinkname

There are many better solutions then this ... but this one is mine. :D Use it or abuse it if you like.
Bye

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment