Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Monday, May 18, 2009

How to move pictures by resolution


This post will help you organize your pictures by resolution into subfolders, making it easier to use with machines that have different monitor size.

I myself like to have my files very organized, and one of the problems I have once in a while is that at home my laptop is always plugged into my widesreen monitor, however when I'm on the road my laptop only supports 1024x800 resolutions. This results in having some of the wallpapers not look good when moving from home setup to road, and vice versa.

So I came up with a simple line of codes using the package “imagemagick”.

1- Make sure that the images have no space in their names. One way of solving this for bulk files is by using 'convert', which also comes with imagemagick:

convert 's/ //g' *

2- Sort items by resolution

# folder with images only
identify * | awk '{ print $3 }' | sort -n

# folder with files and images
for i in $(ls *jpg *png *gif *JPG *JPEG 2> /dev/null) ; do identify "$i" | awk '{ print $3 }' | sort -n ; done

3- You should now get a list of the different resolutions for the pictures in the folder, similar to the one below:

$ identify * | awk '{ print $3 }' | sort -n

1024x768
1024x768
1024x768
1024x768
1024x768
1280x1024
1280x1024
1280x1024
1280x1024
1400x1050
1600x1000
1600x1129

4- Create a folder for each of the resolutions and then set the local variable “_res” with the resolutions of the “turn”:

_res="1024x768"

5- Run the code that will organize the pictures into folders:

for i in "$(identify *jpg *png *gif 2> /dev/null | grep "$_res")" ; do mv $(echo "$i" | awk '{ print $1 }' | sed 's/\[.*\]//g') $_res/ ; done

6- Repeat steps 4 and 5 for the remaining files


No comments: