Getting the size of album artwork
I'm trying to write a script that will churn through my library and give me a playlist of tracks which have oversize artwork, say greater than 300x300. (I mistakenly attached a 2500x2500 jpg to an album yesterday, and iTunes simply crawled - too much for a Mac Mini accessing the files over SMB, I guess)
I can get the artwork fine, with: set thePic to (data of front artwork of theTrack) as picture
But what can I do with thePic to get the dimensions? Surely I don't have to write it as a file, add it to iPhoto, get the dimensions, remove it from iPhoto and then delete the file?
This is probably more a general AppleScript question rather than iTunes - sorry! Of course, if anybody already has a script to do this and doesn't mind sharing, well... :D
Thanks...
# 1 Re: Getting the size of album artwork
There is no builtin way for applescript to access the image dimensions, though I believe there are a couple of extensions which allow access to the dimensions, though they will likely require writing the data out to a file. On the other hand, if the data is uncompressed, you maay be able to get a good estimate of image size based on the size of the data structure (assuming that is availabel through AppleScript).
# 2 Re: Getting the size of album artwork
hi,
not tried it myself but if running Tiger, have you had a look at the Image Events dictionary in the editor, there is a dimensions element in the class of image, it might take the passed variable thePic
hth
Deeg
p.s interesting beta3 work ;)
deeg at 2007-11-15 17:25:15 >

# 4 Re: Getting the size of album artwork
Has anyone had any luck with a script like this?
With eyes toward an Apple TV, I'd like to replace all of the small artwork in my libary with images that are at least 600x600. The higher-rez stuff looks much better on a tv. I'm not concerned with the increased mp3 file size. Space just gets cheaper and cheaper. And I have plenty of room on the ipod at the moment.
# 5 Re: Getting the size of album artwork
Looking at the iTunes SDK, there is no place iTunes exposes the Artwork as an Image.
All we have is SaveArtworkToFile as a method to retrieve the artwork.
Artwork.Item(0) is an Artwork object, not an Image object, and you can't simply cast it to an Image object so I am afraid you can't get dimensions without saving to a file first.
# 6 Re: Getting the size of album artwork
thanks for the response McoreD
Hmmm, would it be possible to do this through the Finder with applescript? Using a combination of applescripts I suppose.
First saving all the artwork using the SaveArtworktoFile Script. Then getting the dimensions of the files somehow.
# 7 Re: Getting the size of album artwork
Just sat down at a 10.4 machine; Image Events cetainly does what you want...just not the way you want ;-)
set file_path to "/Users/stu/Desktop/stupix.jpg" as POSIX file
tell application "Image Events"
set pic_file to open file_path as alias
set pic_dims to dimensions of pic_file
close pic_file
end tell
display dialog ("Width: " & item 1 of pic_dims as string & "; Height: " & item 2 of pic_dims as string)
Tried a bunch of stuff with the clipboard; couldn't coerce into anything that Image Events would deal with (although there were some interesting error messages ;-)
S2_Mac at 2007-11-15 17:30:11 >
