Get Multiple Photo Sizes

I’m looking for someone who might have a snip that will gather the pixel dimensions of multiple photos and generate a text file with those dimensions converted to inches along with the corresponding filename. I know very little about applescript and am really strugling with this one. I’m sure it’s a piece of cake for some of you.
Thanks.

What programs are you using? and how are you “selecting” the photo’s to evaluate?

I’m using Photoshop CS2. I can manually look at the image size and get the size I need, but I have clients that send me a buzillion images that all vary in size. So, as a major time saver, I’m hoping to come up with an applescript that will allow you to select a folder full of images and then evaluate all the images and write it’s findings to a tab-delimited text file that would have filename, dimensions in inches and resolution. (whew.)

The idea is for this to take place in the finder, so the images don’t have to opened. That’s the time consuming part. The finder already holds the pixel by pixel size and dimension. The pixel width divided by resolution would give inch width, etc…

Quickly cobling some snippets together from other scripts:

to MakeList(ProcessFolder)
	tell application "Finder"
		set FileList to (files of entire contents of alias ProcessFolder whose file type is "TIFF" or name extension is "tif" as list)
		return FileList
	end tell
end MakeList
to GetDimensions(TheFile)
	tell application "Image Events"
		set MyImage to open alias TheFile
		set MyResolution to resolution of MyImage
		set MyDimension to dimensions of MyImage
		set InfoList to name of MyImage & "	" & (item 1 of MyDimension) / (item 1 of MyResolution) & "	" & (item 2 of MyDimension) / (item 2 of MyResolution) & return
		close MyImage
	end tell
	return InfoList
end GetDimensions
set ProcessFolder to (choose folder) as string
set FileList to MakeList(ProcessFolder)
set MyPath to ((path to desktop folder) as string)
set logfile to MyPath & "Image_Log.txt"
open for access file logfile
close access file logfile
set MyList to ""
repeat with AnItem in FileList as list
	set MyList to MyList & (GetDimensions(AnItem as string))
end repeat
open for access file logfile with write permission
write MyList to file logfile
close access file logfile

save as an application, double click on it anc choose the folder to process. Works only on tif images and builds a list with the image name tab width tab height. Saves a log file to the desktop.

AWESOME! :lol:
Works great.
Now, I’ve got to figure a way to make it work with the top 3 file types: .tif, .eps, .jpg.
I’m going to try and figure it out myself, but I’m all ears if you have any advice. :smiley:

to MakeList(ProcessFolder)
	tell application "Finder"
		set FileList to (files of entire contents of alias ProcessFolder whose file type is "TIFF" or file type is "EPSF" or file type is "JPEG" or name extension is "tif" or name extension is "eps" or name extension is "jpg" as list)
		return FileList
	end tell
end MakeList
to GetDimensions(TheFile)
	tell application "Image Events"
		set MyImage to open alias TheFile
		set MyResolution to resolution of MyImage
		set MyDimension to dimensions of MyImage
		set InfoList to name of MyImage & "    " & (item 1 of MyDimension) / (item 1 of MyResolution) & "    " & (item 2 of MyDimension) / (item 2 of MyResolution) & return
		close MyImage
	end tell
	return InfoList
end GetDimensions
set ProcessFolder to (choose folder) as string
set FileList to MakeList(ProcessFolder)
set MyPath to ((path to desktop folder) as string)
set logfile to MyPath & "Image_Log.txt"
open for access file logfile
close access file logfile
set MyList to ""
repeat with AnItem in FileList as list
	set MyList to MyList & (GetDimensions(AnItem as string))
end repeat
open for access file logfile with write permission
write MyList to file logfile
close access file logfile

Not the cleanest code or the best solution possible but it should work as long as you don’t throw illustrator or freehand files at it.

Am getting this error:
“Finder got an error: Can’t make some data into the expected type.”

from this line:

set FileList to (files of entire contents of alias ProcessFolder whose file type is "TIFF" or name extension is "tif" as list)

???

Not sure and no text file, but if you want try this one.
http://www.audioequipment.it/abc/PUB.dmg

I’ve built this little application myself with Applescript. I’m a newbie of AS as you :slight_smile:

don’t pass .eps to image events have other app (PS CS2) handle these file types. Create 2 file lists have one pass .jpeg & .tiff to IE and the other pass .eps to PS. I have some code for this somewhere I will attempt to dig it out.

I too am getting an error on eps files. Checking into it.

I have tried to quickly dumb down what I had to do this to suit what you wanted. This should get you the 2 lists you can then pass this on.

property Rast_CT : {missing value, "8BIM"} -- Photoshop or unknown creator types
property Vect_CT : {"ART5", "CARO", "XPR3"} -- Other known EPS creator types
property FileTypeList : {"JPEG", "TIFF"} -- Your Image Events file type choice
property Ext_List : {missing value, "jpg", "jpeg", "tif", "tiff"} -- Your Image Events extensions choice
--
set inputFolder to choose folder with prompt "Where's the images folder?"
--
tell application "Finder"
	set MyImageFiles to (every file of entire contents of inputFolder) as alias list
end tell
--
set PS_List to {}
set IE_List to {}
--
tell application "Finder"
	repeat with this_item in MyImageFiles
		set X to properties of this_item
		--
		if name extension of this_item is "eps" or ¬
			file type of this_item is "EPSF" and ¬
			creator type of this_item is in Rast_CT then ¬
			copy (this_item as string) to end of PS_List
		--
		if name extension of this_item is in Ext_List or ¬
			file type of this_item is in FileTypeList and ¬
			creator type of this_item is in Rast_CT then ¬
			copy (this_item as string) to end of IE_List
	end repeat
end tell

Just noticed you probably won’t need property 2 it was for rasterizing vectors else where.

If I modify Jerome’s original AppleScript to search for PDFs, and their color space, Image Events returns a false “RGB” for grayscale and CMYK PDF’s.

to MakeList(ProcessFolder)
	tell application "Finder"
		set filelist to (files of entire contents of alias ProcessFolder whose file type is "PDF" or name extension is "pdf" as list)
		return filelist
	end tell
end MakeList
to GetDimensions(TheFile)
	tell application "Image Events"
		set MyImage to open alias TheFile
		set MyResolution to resolution of MyImage
		set MyDimension to dimensions of MyImage
		set MyColorspace to color space of MyImage
		set InfoList to name of MyImage & "    " & MyResolution & "    " & MyColorspace & "    " & (item 1 of MyDimension) / (item 1 of MyResolution) & "    " & (item 2 of MyDimension) / (item 2 of MyResolution) & return
		close MyImage
	end tell
	return InfoList
end GetDimensions

set ProcessFolder to (choose folder) as string
set filelist to MakeList(ProcessFolder)
set MyPath to ((path to desktop folder) as string)
set MyList to ""

repeat with AnItem in filelist as list
	set MyList to MyList & (GetDimensions(AnItem as string))
end repeat

tell application "TextEdit"
	make new document at beginning with properties {text:MyList as Unicode text}
	activate
end tell

I just need sizes on tif, eps, jpg files really. A pdf seems to be filled with an infinite array of variables.

Strange, I don’t remember writing this script…is what I wrote working for the original purpose? What are the problems that people are having? With the PDF if might be that image events is reading an RGB composit preview image and not the PDF itself, thus returning a false color space. You might have to go to preview or even acrobat to get accurate information on the PDF, or delve deep into the Adobe PDF specs and find the appropriate code to read in the PDF to get the information. The problem that I can see is that there might be multiple color spaces for various images embeded in the PDF. I would imagine that the best way to check it would be using Acrobat for this reason, both in writing the script and accuratly processing the file. Just guessing here, I will check back to see how things are progressing.

Jerome

Again. Not interested in pdf’s. Don’t worry about it just for me. Only TIF, JPG, EPS, ya’ know bitmap formats.
Your script works on TIF’s and JPG’s. Not EPS’s

This appears to be working for me in a few basic tests that I’ve run. You may want to include a handler to round down the inch measures.

property Rast_CT : {missing value, "8BIM"} -- Photoshop or unknown creator types
property FileTypeList : {"JPEG", "TIFF"} -- Your Image Events file type choice
property Ext_List : {missing value, "jpg", "jpeg", "tif", "tiff"} -- Your Image Events extensions choice
--
set inputFolder to choose folder with prompt "Where's the images folder?"
--
tell application "Finder"
	set MyImageFiles to (every file of entire contents of inputFolder) as alias list
end tell
--
set PS_List to {}
set IE_List to {}
--
tell application "Finder"
	repeat with this_item in MyImageFiles
		set X to properties of this_item
		--
		if name extension of this_item is "eps" or ¬
			file type of this_item is "EPSF" and ¬
			creator type of this_item is in Rast_CT then ¬
			copy (this_item as string) to end of PS_List
		--
		if name extension of this_item is in Ext_List or ¬
			file type of this_item is in FileTypeList and ¬
			creator type of this_item is in Rast_CT then ¬
			copy (this_item as string) to end of IE_List
	end repeat
end tell
--
repeat with aFile in IE_List
	tell application "Finder"
		set theFile to aFile as alias
		set docName to name of theFile
	end tell
	tell application "Image Events"
		set ThisImage to open theFile
		set docMode to get color space of ThisImage
		set docRes to get resolution of ThisImage
		set docDims to get dimensions of ThisImage
		set docWidth to (item 1 of docDims) / (item 1 of docRes)
		set docHeight to (item 2 of docDims) / (item 2 of docRes)
		if (item 1 of docRes) = (item 2 of docRes) then
			set docRes to (item 1 of docRes)
		else
			set docRes to (item 1 of docRes) & tab & (item 2 of docRes)
		end if
		writelog(docName, docMode, docWidth, docHeight, docRes) of me
		close theFile saving no
	end tell
end repeat
--
tell application "Adobe Photoshop CS2"
	set display dialogs to never
	set UserPrefs to properties of settings
	set ruler units of settings to inch units
end tell
--
repeat with aFile in PS_List
	tell application "Finder"
		set theFile to aFile as alias
	end tell
	tell application "Adobe Photoshop CS2"
		activate
		open theFile
		set docRef to the current document
		tell docRef
			set docName to name of docRef
			set docMode to mode
			set docWidth to width
			set docHeight to height
			set docRes to resolution
			writelog(docName, docMode, docWidth, docHeight, docRes) of me
		end tell
		close current document without saving
	end tell
end repeat
--
tell application "Adobe Photoshop CS2"
	set ruler units of settings to ruler units of UserPrefs
end tell
--
set ReadFile to ((path to desktop folder) as text) & "Image Info Log.txt" as alias
tell application "TextEdit"
	activate
	open ReadFile
end tell
--
on writelog(docName, docMode, docWidth, docHeight, docRes)
	set theLog to ((path to desktop folder) as text) & "Image Info Log.txt"
	try
		open for access file the theLog with write permission
		write (return & docName & tab & docMode & tab & docWidth & tab & docHeight & tab & docRes) to file the theLog starting at eof
		close access file the theLog
	on error
		try
			close access file the theLog
		end try
	end try
end writelog