Droplet to get the dimensions of an image?

Hi all, I’m trying to write (and getting nowhere fast) a droplet to get the width and height of an image and set it to the clipboard.
If it’s possible, I would like this html tag set to the clipboard.

If not, just the width and height of an image set to the clipboard would be great.

Any and all help is very much appreciated!

Tom

Browser: Safari 525.18
Operating System: Mac OS X (10.4)

Hi Tom,

… a basic one without error trapping

on open f
	set p to quoted form of (POSIX path of f)
	set fname to (do shell script " basename " & p)
	set hw to paragraphs of (do shell script "mdls " & p & " | awk -F \"= \" '/kMDItemPixel(Height|Width)/{print $2}'")
	set the clipboard to "<img src=\"" & fname & "\" width=\"" & hw's item 2 & "\" height=\"" & hw's item 1 & "\" alt=\"\" />"
end open

hth

Hi clemhoff, Thanks, but I’m getting the following error…
Can’t make item 2 of {“”} into type Unicode text.

Tom

Browser: Safari 525.18
Operating System: Mac OS X (10.4)

Tom,

what result do you get if you open a Terminal window, type mdls_ (the underscore represents a space), drag your image on this window and press the “Enter” key ?

…I hope you will be luckier with “Image Events”

on open f
	if (count f) = 1 then
		set fname to name of (info for f)
		try
			tell application "Image Events"
				launch
				set img to open (f as string)
				set {w, h} to img's dimensions
				close f
			end tell
			set the clipboard to "<img src=\"" & fname & "\" width=\"" & (w as integer) & "\" height=\"" & (h as integer) & "\" alt=\"\" />"
		on error errtxt
			display dialog errtxt
		end try
	else
		display dialog "One file at the time !" buttons "OK" default button 1
	end if
end open

Hi clemhoff,

Thank you! Your script runs perfectly.

I really appreciate you taking the time to help me.

Tom

Browser: Safari 525.18
Operating System: Mac OS X (10.4)