Apple Script's Image Events knows about dimensions, but otherwise AppleScript is clueless about it. Image Events is slow to get the dimensions too, as the following Automator code will have processed three files in the time it takes Image events to open and get the dimensions on one file.
You have coded a Service, but that is the wrong structure to take arguments in from a preceding action.
I just tested the following Run AppleScript action taking input from Ask for Finder items, where I selected three image files in a folder.
Before:
After:
The Automator application workflow:
Replace the contents of a Run AppleScript action with the following copy/pasted code. It uses AppleScript Objective-C and that is a key to its speed.
use framework "Cocoa"
use AppleScript version "2.4"
use scripting additions
property NSString : a reference to current application's NSString
property NSBitmapImageRep : a reference to current application's NSBitmapImageRep
on run argv
if (count of argv) = 0 then return
tell application "Finder"
repeat with anImg in (item 1 of argv)
set name_ext to name of anImg
set wxh to my img_dimensions(anImg) as text
if class of wxh is boolean then
log "foo"
else
set wxh to space & wxh
set name of anImg to my append_dimensions(name_ext, wxh) as text
end if
end repeat
end tell
return
end run
on img_dimensions(afile)
set imgRep to NSBitmapImageRep's imageRepsWithContentsOfFile:(POSIX path of afile)
set width to (imgRep's pixelsWide) as integer
set height to (imgRep's pixelsHigh) as integer
if width > 0 and height > 0 then
return (width & "x" & height) as text
else
return false
end if
end img_dimensions
on append_dimensions(afile, dimensions)
set fileStr to NSString's stringWithString:(POSIX path of afile)
set ext to fileStr's pathExtension()
set filebase to (fileStr's stringByDeletingPathExtension)'s stringByAppendingString:dimensions
return ((filebase's stringByAppendingPathExtension:ext)'s lastPathComponent()) as text
end append_dimensions