Skip to content

Instantly share code, notes, and snippets.

@simonhlee97
Created January 4, 2024 12:32
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 simonhlee97/fb412bd2eae89587b2e4bb4f73472d2b to your computer and use it in GitHub Desktop.
Save simonhlee97/fb412bd2eae89587b2e4bb4f73472d2b to your computer and use it in GitHub Desktop.
bash script to resize images
#!/bin/bash
# Set the input and output directories
input_dir="input"
output_dir="output"
# Create the output directory if it doesn't exist
mkdir -p "$output_dir"
# Iterate over each JPG file in the input directory
for file in "$input_dir"/*.jpg; do
# Get the filename without extension
filename=$(basename -- "$file")
filename_noext="${filename%.*}"
# Perform resizing using convert command
convert "$file" -resize 400x300 "$output_dir/$filename_noext"_resized.jpg
echo "Processed: $filename"
done
echo "Script completed."
#### save this file in project directory.
#### run the 2 commands below to run the script.
#### #### chmod +x your_script.sh
#### #### ./your_script.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment