Created
January 4, 2024 12:32
-
-
Save simonhlee97/fb412bd2eae89587b2e4bb4f73472d2b to your computer and use it in GitHub Desktop.
bash script to resize images
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 | |
# 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