classifying images based on size and resolution

i have tons of images that i need to classify somehow, and i don’t have the time to open them one by one to check if they are in the right resolution or size…
i need them to be: at least 1500x1500 px, OR above 200 dpi, or above 20cm x 20cm.
( that way, any image is good for printing, whether i have to resample it or not… )
here is what i’ve got so far…


set inputFolder to choose folder with prompt "Select image folder" without invisibles
tell application "Finder"
	set fileList to files in inputFolder
end tell
try
	repeat with theFile in fileList
		tell application "Finder" to set aFile to theFile as alias
		tell application "Image Events"
			launch
			set thisImage to open file (aFile as string)
			set fileDimensions to dimensions of thisImage
			if item 1 of fileDimensions < 1500 or item 2 of fileDimensions < 1500 then
				tell application "Finder" to set label index of theFile to 2
			end if
			close thisImage without saving
		end tell
	end repeat
on error err
	display dialog err
end try

as you can see, the images below 1500x1500 px are labeled in RED.
i was going to add the dpi check when i found out that there’s no way to measure the printing size of an image with Image Events…
and, i can’t figure out a way to add files in subfolders to the fileList

any ideas?

thank you very much guys…

marto.

I would use Spotlight to do it:

set OKPic to (do shell script "mdfind -onlyin /Users/bellac/Pictures/ 'kMDItemPixelWidth >= 1500 && kMDItemPixelHeight >= 1500 || kMDItemResolutionHeightDPI >= 200'")

What that statement says is that to be included, a pic must be at least 1500 pixels wide AND 1500 pixels high OR have a vertical resolution of at least 200 pixels per inch". && is AND, || is OR and the spotlight metadata for a jpeg sampled at random from my collection in Pictures for example are given below. (I’m mid-way through an article on how to use Spotlight from AppleScripts for the tutorial to appear in MacScripter.net - due a couple of weeks from now.)

-onlyin /Users/bellac/Pictures/ limits the scope of the search to my Pictures folder. If you remove it, it will search all mounted volumes. Don’t do it on a network volume. Change the Posix path to point to your Pictures folder.

The shell script returns a list of the posix paths to all the files found. You’d use a repeat to go through them

repeat with aPic in OKPic
	set Pic to POSIX file (contents of aPic)
	-- do your stuff to pic
end repeat

wow… i didn’t know Spotlight could search THAT kind of metadata…

lets see… so, in your statement “OKpic” is a list of files wich have the searched parameters?

i mean… i’m a little lost here. how do i make the finder to change the label color on the result of the serach?

thanks.

marto.

Hi marto,

you can do it with this:

set OKPic to paragraphs of (do shell script "mdfind -onlyin /Users/myUser/Pictures/ 'kMDItemPixelWidth >= 1500 && kMDItemPixelHeight >= 1500 || kMDItemResolutionHeightDPI >= 200'")
repeat with i in OKPic
	set thePic to POSIX file i
	tell application "Finder" to set label index of thePic to 2
end repeat

great! now i get it…
but how can i do for it to prompt me for the folder in wich to do the search?

will something like this work?


set inputFolder to choose folder with prompt "Select image folder" without invisibles as POSIX

set OKPic to (do shell script "mdfind -onlyin " & inputFolder & " 'kMDItemPixelWidth >= 1500 && kMDItemPixelHeight >= 1500 || kMDItemResolutionHeightDPI >= 200'")

thanks!!!

This is better (and safer in case an address has a space in it):


set inputFolder to quoted form of POSIX path of (choose folder with prompt "Select image folder" without invisibles)
set OKPic to (do shell script "mdfind -onlyin " & inputFolder & " 'kMDItemPixelWidth >= 1500 && kMDItemPixelHeight >= 1500 || kMDItemResolutionHeightDPI >= 200'")
repeat with i in OKPic
	set thePic to POSIX file i
	tell application "Finder" to set label index of thePic to 2
end repeat

almost :wink:

set inputFolder to choose folder with prompt "Select image folder" without invisibles
set OKPic to (do shell script "mdfind -onlyin " & quoted form of POSIX path of inputFolder & " 'kMDItemPixelWidth >= 1500 && kMDItemPixelHeight >= 1500 || kMDItemResolutionHeightDPI >= 200'")