Sort images into two folders based on width x height ratio?

Basicly, I need to sort a bunch of jpegs based on the files width x height to seperate all the 4:3 Desktop Picture sized photos into one folder and the rest leave them there or into a second folder. How would I go about doing this? I figure that I would need to:

  1. call sips from the applescript (as “sips -g pixelWidth -g pixelHeight {file x}”)

  2. parse the pixelWidth and pixelHeight lines (When I run it, I always get :


Chaos@tic:~/pic/ sips -g pixelWidth -g pixelHeight 002.jpg 003.jpg 005.jpg
/Users/Geo/pic/002.jpg
## Component Manager: attempting to find symbols in a component alias of type (imdc/MP42/MSFT)
  pixelWidth: 1002
  pixelHeight: 666
/Users/Geo/pic/003.jpg
  pixelWidth: 669
  pixelHeight: 1002
/Users/Geo/pic/005.jpg
  pixelWidth: 512
  pixelHeight: 768

With this error “## Component Manager: attempting to find symbols in a component alias of type (imdc/MP42/MSFT)” on the second line, regardless of how many files I give it.)

  1. Make sure that Width is greater then Height

  2. a) If width is greater then Height, then compare width over height to 4 over 3 (Compare Ratios)

  3. b) if width is less then height move file to folder1

  4. a) If Ratios match, move to folder2

  5. b) if ratios do not match, move to folder1 (Or a Third Folder)

  6. Repeat till folder is done.

I know I would also need to check it see if Folder1,2,and 3 exist within the main folder, and if not, create them. Also needs to not overwrite a picture, if duplicate name is in a folder, add .1 or .2 or .n to the end of the file name.

Finally, this isn’t required, but if there could be a tolerence built into the ratio checking.

Any and all help would be appreciated. Instruction rather then the answer would be even moreso appreciated

I don’t know about the sips thing, but wouldn’t it be better to check height over width (.75). You could do this using Image Capture Scripting to get the height and width or some other app also.

gl,

You can try scripting Image Events, instead of sips, which will allow you to get the pixel dimensions fairly easily. Here’s the gist of what you need, but modify it to repeat with each of the images:


tell application "Image Events"
	launch
	set theImage to open file "path:to:file.jpg"
	set theDimensions to (dimensions of theImage) --list of 2 numbers, {width, height}
	close theImage
end tell
set W to item 1 of theDimensions
set H to item 2 of theDimensions 
--go from there....

Image Events actually uses sips under the hood, but it’s a lot easier to work with.

http://www.apple.com/applescript/imageevents/index.html