This Bash script processes PNG images in the current directory. It renames images that are already 1600x900 with a _1600x900.png
suffix. For images that are larger, it crops them to 1600x900 from the center and saves them with the same suffix.
To install ImageMagick on Ubuntu, run:
sudo apt-get update
sudo apt-get install imagemagick
-
Save the script to a file, e.g.,
process_images.sh
. -
Make the script executable:
chmod +x process_images.sh
-
Find the dimensions of all png files in the directory:
for file in *.png; do identify -format "%f: %wx%h\n" "$file" done
-
Adjust the dimensions in the script
-
Run the script in the directory containing your PNG files:
./process_images.sh
-
cleanup
find . -maxdepth 1 -type f -name "*.png" ! -name "*_1600x900.png" -print0 | xargs -0 rm
The script performs the following actions:
- Iterates over all
.png
files in the current directory. - Checks the dimensions of each file using
identify
from ImageMagick. - If the image is 1600x900, it renames the file by appending
_1600x900.png
. - If the image is larger, it crops the image to 1600x900 from the center using
convert
from ImageMagick and saves it with the_1600x900.png
suffix.
Given the following files in the directory:
006_inspect-testcase-arguments.png: 1600x900
007_eplore-test-explorer.png: 1600x900
008_adjust-InvokeWorkflow-arguments_WRONG.png: 1626x926
After running the script, the directory will contain:
image1_1600x900.png
image2_1600x900.png (cropped from 1920x1080)
image3_1600x900.png
Christian Prior-Mamulyan [email protected]
This script is released under the Creative Commons Attribution 4.0 International License (CC-BY)