Sorting the images

So now you have downloaded a lot of images, you need to sort the. Perhaps you have downloaded many you do not like. Perhaps they are not the right size or you want to sort them by size, orientation or subject. This can be done manually or automatically, depending on what is possible and how many there are.


I use geeqie to sort manually. I have tried several, but for my purpose this is the best. I go to the directory and select the first image. With the right arrow, I go from image to image. With 1 I select the images I want to keep.

I can user 1 till 0. So I could select up to 10 ways to sort things. e.g 1 is mountains, 2 is head shots, 3 is body shots, 4 is multiple people, 5 is cars and 6 is various and so on. Or 1 needs no editing, 2 needs a resize, 3 will be used with a script. You can do whatever you want. And with your right hand on the arrows and your left hand on the numbers on top, or left on arrows and right hand on numbers, this can go very, very fast. I can get to 2 per second, so going through even 2000 of them goes reasonably fast.

Once you have marked them, you do CTRL+1 to select all with mark 1 and move them to wherever you desire. Then the same for 2 and all the others if there are any others. Once they are selected, you can delete all those that you did not select. Or you mark the ones that you want to delete and keep the rest.

Just do not forget that if you have automated download, there will be others coming in, so move the ones you need.


Sorting can also be done automagically. If you can measure it, you can sort it. This can include, but is not limited to:

  • Width
  • Height
  • Portrait or landscape
  • Average color
  • Name
  • Type
  • Comments

The main tools to turn these into a script a identify and jhead. The first is from imageMagick and will read a LOT of information from the EXIF metadata. Especially with the -verbose option. Not only the size, but any other information, including comments, camera, ISO used and anything else that is available. The second shows a lot less, but can be a bit faster. I personally just filter on width, height and ratio of 16/9. The ratio can also be used to see if something is landscape, portrait or just a square.

To get the width, the height and the ratio, this is what you can do:

for FILE in $(find $DIR -type f)
    WIDTH=$(identify -format %w $FILE)
    HEIGHT=$(identify -format %h $FILE)
    RATIO=$(echo "scale=0; $WIDTH*100/$HEIGHT"|bc)
    echo "$FILE
ratio is $RATIO


And then you can use if statements in the scripts to move them anywhere, depending on the output. So I get this:

RT=$(scale=5;echo '16/9'|bc -l)

for FILE in $(find $REAL_DIR -type f)
	WIDTH=$(identify -format %w $FILE)
	HEIGHT=$(identify -format %h $FILE)
	RATIO=$(echo "scale=0; $WIDTH*100/$HEIGHT"|bc)
#	Ratio > 2.00 or < 0.70 : Manual
	if [ "$RATIO" -gt "200" ] || [ "$RATIO" -lt "70" ]
# 	Ratio < 1.00 or smaller than 1600 x 800 : Make It
	elif [ "$RATIO" -lt "100" ] || [ "$WIDTH" -lt "1600" ] || [ "$HEIGHT" -lt "800" ]
		mv $FILE $PRT1_DIR/
#	Ratio ! 1.77 : Make It
	elif [ "$RATIO" != "177" ]
		NEWHIGHT=$(echo "$WIDTH/$RT"|bc)
		mogrify -resize ${WIDTH}x${NEWHIGHT}^ -gravity center -crop ${WIDTH}x${NEWHIGHT}+0+0 $FILE

This sorts the files where I want them. The mogrify command will also resize the image to a 16/9 ratio. So if a file is portrait, I will put it in a directory for further processing. If the file is too out of ratio (e.g. way too wide, it will be treated manually. This because perhaps the interesting part is not in the middle. Just imagine a picture of the Eiffel tower on a door poster. You will see the middle, but not the top or the bottom and that is something you might want to see. So now I have three directories.

  • One that needs to do images manually
  • One that has the 16/9 ratio images
  • One that needs further processing

So further processing is making the wallpapers.