ImageMagick – Sort wallpapers the easy way

If you happen to have a very large collection of wallpapers with mixed up resolutions then think no further. ImageMagick comes to your resuce to help you sort the wallpapers based on the resolutions.
According to the makers of ImageMagick :
ImageMagick® is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. Use ImageMagick to scale, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.
I have put together a little shell script which will help you sort you wallpaper collection according to resolution.
#!/bin/bash
#
#Wallpaper Sorter v2
#This script is bought to you by 7sins@4geeksfromnet.com
#
#Use this to sort wallpapers according to resolutions
#
#This script when run in a folder full of wallpapers
#1. Determines the resolution of each wallapaper (can be either jpg, gif, png, bmp)
#2. Verifies if a folder with the same name as the resolution exists.
# If the folders exists => Move the wallpaper into that folder
# If the folder does not exists => Create the folder and then move the wallpaper into that folder
#3. Requires ImageMagick
LOCATION="$1"
echo "Moving into location $LOCATION"
cd "$LOCATION"
for file in *.jpg -o *.JPG -o *.gif -o *.GIF -o *.jpeg -o *.png -o *.bmp -o *.BMP
do
#Get the image resolution
resolution=$(identify -verbose "$file" | grep Geometry | awk '{ print $2}' | cut -f -1 -d\+)
# Create a folder with the name of the resolution if it does not exist
if ! test -d "${resolution}"
then
mkdir -p $resolution
echo "Created folder $resolution"
fi
#Move the file into the folder, name of which is same as the resolution
echo "Moving $file to folder $resolution"
mv "$file" "$resolution"
done
How to get the script up and running :
- Copy the script code and make it executable
:~$ chmod a+x sortPicsv2.sh
-
Execute the script using
:~$ ./sortPicsv2.sh /home/username/path_to_wallpapers_folder
Replace the path /home/username/path_to_wallpapers_folder with the actual location of your wallpapers collection.
Happy sorting
Hi, you can write a shell script for sorting… *.jpg or *.png or *.raw ?
I’m afraid my English is a bit rusty.
best regards, little
Do you want to sort the images by extension from a bunch of files ?