Skip to content

Instantly share code, notes, and snippets.

@jvyden
Created April 13, 2023 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvyden/42c15477b8a752804d02997847542372 to your computer and use it in GitHub Desktop.
Save jvyden/42c15477b8a752804d02997847542372 to your computer and use it in GitHub Desktop.
#!/bin/bash
# generate a random 12-character string
output_dir="output"
# create the output directory
mkdir "$output_dir"
# loop through all the .jpg and .png files in the current directory
for file in *.jpg *.png *.jpeg; do
# get the file extension
ext=${file##*.}
# check if the file is a .jpg or .png
if [[ "$ext" == "jpg" || "$ext" == "png" || "$ext" == "jpeg" ]]; then
# resize the image to fit within 640x480 and save it as a .png file in the output directory
convert "$file" -resize 640x480 "$output_dir/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 12 | head -n 1).png"
fi
done
# loop through all the .png files in the output directory
for file in "$output_dir"/*.png; do
# run the "optipng" utility on the file to optimize its size
optipng "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment