Skip to content

Instantly share code, notes, and snippets.

@Sansui233
Created December 1, 2020 17:46
Show Gist options
  • Select an option

  • Save Sansui233/21492f8132897d0a3d260ae675c51377 to your computer and use it in GitHub Desktop.

Select an option

Save Sansui233/21492f8132897d0a3d260ae675c51377 to your computer and use it in GitHub Desktop.
fix image width to 640px with ffmpeg
echo "Fix your images width into 640px"
path=$(pwd)
cd $path
echo "\033[34m[Info] Workdir: $path" $(tput sgr0)
files=$(ls $path)
for filename in $files
do
echo "\033[34m[Info] Converting $filename ........." $(tput sgr0)
filenameNoExtension="${filename%.*}"
fileExtension="${filename##*.}"
if [[ "$fileExtension" = "PNG" || "$fileExtension" = "png" ]]; then
ffmpeg -i $filename -vf scale=640:-1 $filenameNoExtension.jpg -y >/dev/null 2>&1
rm $filename
elif [[ "$fileExtension" = "jpg" || "$fileExtension" = "JPG" ]]; then
ffmpeg -i $filename -vf scale=640:-1 $filename -y >/dev/null 2>&1
else
echo "\033[33m[WARNING] Unsupported format" $(tput sgr0)
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment