Indesign CS2 get size of placed image

Hi all,
I would like to know how you get the size of a placed image? I’m placing an image in a picture box in Indesign CS2, I would then like to be able to check if the file I’ve placed is larger than the box I’ve placed into and if it is, fit it proportionally, otherwise just centre the content.

property therectangle : {74, 6.728, 290.937, 204}

set this_item to choose file

tell application "Adobe InDesign CS2"
	activate
	tell page 1 of document 1
		set myRectangle to make rectangle with properties {geometric bounds:therectangle, stroke weight:0}
		tell myRectangle
			place this_item
			(* Here is where I would like to say 
			if this_item is > than myRectangle then
			fit this_item_alias given proportionally
			else
			fit this_item_alias given center content
			end if*)
		end tell
	end tell
end tell

Thanks in advance

Hi blend,

you can get the dimensions of an image with

set this_item to choose file
tell application "Image Events"
	try
		open this_item
		set {picWidth, picHeight} to dimensions of image 1
		close image 1
	end try
end tell

Hi Stefan,
thanks for the advise but I think I need to do this in Indesign, the file that I’m placing within Indesign could either be a PDF or an EPS (this could be a vector file not necessarily rastored). Once the file has been placed in myRectangle I need to know if it’s larger than the size of myRectangle. Sorry if the use of the word image was misleading.

tell application "Adobe InDesign CS2"
	set ImageRecord to {ImageLabel:"", TheHeight:0, TheWidth:0, ColorSpace:"", TheResolution:{}}
	activate
	tell document theDoc
		tell page ThePage
			place (FilePath of TheImage) on rectangle ("Image " & boxcounter)
			set ImageBounds to geometric bounds of all graphics of rectangle ("Image " & boxcounter)
			set TheHeight of ImageRecord to (item 3 of ImageBounds) - (item 1 of ImageBounds)
			set TheWidth of ImageRecord to (item 4 of ImageBounds) - (item 2 of ImageBounds)
		end tell
	end tell
end tell

From a script that I am working on, change the variables to match yours and test for height and width based off of your rectangle.

Hi Jerome,
thanks for the post but I’m having trouble getting this to work with my variables.

property therectangle : {74, 6.728, 290.937, 204}
set this_item_alias to choose file

tell application "Adobe InDesign CS2"
	set ImageRecord to {ImageLabel:"", TheHeight:0, TheWidth:0, ColorSpace:"", TheResolution:{}}
	activate
	tell document 1
		tell page 1
			set myRectangle to make rectangle with properties {geometric bounds:therectangle, stroke weight:0}
			tell myRectangle
				place this_item_alias
			end tell
			--place (FilePath of TheImage) on rectangle ("Image " & boxcounter)
			set imageBounds to geometric bounds of all graphics of rectangle myRectangle --("Image " & boxcounter)
			set TheHeight of ImageRecord to (item 3 of imageBounds) - (item 1 of imageBounds)
			set TheWidth of ImageRecord to (item 4 of imageBounds) - (item 2 of imageBounds)
		end tell
	end tell
end tell

it’s erroring on the set imageBounds line with an invalid parameter, any ideas?

try this

.
set myRectangle to make rectangle with properties {geometric bounds:therectangle, stroke weight:0}
			tell myRectangle
				set thisgraphic to place this_item_alias
			end tell
			--place (FilePath of TheImage) on rectangle ("Image " & boxcounter)
			set imageBounds to geometric bounds of thisgraphic
			set TheHeight of ImageRecord to (item 3 of imageBounds) - (item 1 of imageBounds)
			set TheWidth of ImageRecord to (item 4 of imageBounds) - (item 2 of imageBounds)
.

Hi Stefan,
with a little tweak it works. Thanks very much for your help Stefan and Jerome :smiley:

set this_item_alias to choose file
property therectangle : {74, 6.728, 290.937, 204}


tell application "Adobe InDesign CS2"
	set ImageRecord to {TheHeight:0, TheWidth:0}
	activate
	set mydoc to active document
	tell mydoc
		set myRectangle to make rectangle with properties {geometric bounds:therectangle, stroke weight:0}
		tell myRectangle
			set thisgraphic to place this_item_alias
		end tell
		set imageBounds to geometric bounds of thisgraphic
		set TheHeight of ImageRecord to (item 3 of imageBounds) - (item 1 of imageBounds)
		set TheWidth of ImageRecord to (item 4 of imageBounds) - (item 2 of imageBounds)
	end tell
end tell