Does a method exist to directly sample iTunes artwork data?

My car has a lag displaying image artwork greater than about 500px², so I need a way to identify tracks with oversized art. I have a working method, but it involves saving each individual artwork as bytes, testing their dimensions, resizing, reading it back as «class data», and relinking to the track. This is cumbersome, as some tracks are already within spec, and my library is large. Is there a way to poll image sizes en masse without the intermediate file realization? Thanks.

I bet there is. I’d suggest a visit to Doug’s place.

Managing Artwork 1 2 3

A little poking around on Doug’s site turned up this handler…

Doug’s AppleScripts » Spare Parts

It looks like this handler from Doug does what you need, but maybe not what you want, or the way you want it.

Basically, it seems appleScript can “see” the raw image data for the artwork. This script saves the raw image data in a new image file (on the desktop) and from there you could use image events or other tools to get the dimensions you need.


--Source: https://dougscripts.com/itunes/scripts

tell application "Music"
	set sel to (first item of selection)
	
	# pass (iTunes track reference, path to folder as text, name of file as text)
	my exportArtwork_(sel, (path to desktop from user domain) as text, "myartworkpic")
end tell

to exportArtwork_(theTrack, exportFolder, artworkName)
	tell application "Music"
		try
			tell theTrack to set {artworkData, imageFormat} to {(raw data of artwork 1), (format of artwork 1) as text}
		on error
			# probably no artwork
			return false
		end try
	end tell
	
	set ext to ".png"
	set fileType to "PNG"
	if imageFormat contains "JPEG" then
		set ext to ".jpg"
		set fileType to "JPEG"
	end if
	
	set pathToNewFile to (exportFolder & artworkName & ext) as text
	
	# if file with same name exists in same location then delete it
	# optional
	try
		do shell script "rm " & quoted form of POSIX path of pathToNewFile
	end try
	
	try
		set fileRef to (open for access pathToNewFile with write permission)
		set eof fileRef to 0
		write artworkData to fileRef starting at 0
		close access fileRef
	on error m
		try
			close access fileRef
		end try
		return false
	end try
	
	try
		tell application "System Events" to set file type of (pathToNewFile as alias) to fileType
	on error m
		# may not be critical
		log ("ERROR: " & m)
	end try
	
	return true
	
end exportArtwork_

Thanks, estockly, but that’s more or less my current method. If a script can read the data, there should be a way to extract info from it without a physical representation.

Well, that’s beyond my scripting ability and, apparently, Doug’s.

But, what’s wrong with saving it as a file? You can save it in temporary items get your info and never think about it again. I takes a fraction of a second to write and read (iTunes artwork aren’t big files, as you know).

Like I said, this does what you need, but not the way you want

Doug’s scripts :

Sort by artwork size: (it can apply the size
To a tag or move tracks of a certain size to a playlist)

https://dougscripts.com/itunes/scripts/ss.php?sp=mxsortbyartworksize

Reapply downsized artwork: selected files or selected playlist tracks
Are scanned for artwork size set by user. If larger
The image is resized and reapplied, other options also available

https://dougscripts.com/itunes/scripts/ss.php?sp=mxreapplydownsized

The tagging app Kid3 has a automatic user action script
Which will resize embedded artwork to 500x500.
I use this all the time

Doug is one of appleScript’s unsung heroes.