[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(DTPtechNote:1215) Re: [AS Indesign CS & Photoshop CS] リサイズして再リンク


set my_resolution to 200 --原寸200dpi
set yohaku to 1 * 2 --余白値

tell application "InDesign CS_J"
	tell document 1
		set my_every_selection to object reference of selection
		repeat with my_selection in my_every_selection
			tell my_selection
				set tmp_bounds to geometric bounds
				set x1 to item 2 of tmp_bounds
				set x2 to item 4 of tmp_bounds
				set y1 to item 1 of tmp_bounds
				set y2 to item 3 of tmp_bounds
				set geometric bounds to {y1, x1, (y2 - yohaku), (x2 - yohaku)} --大きさを変更
				set frame_x to (item 4 of tmp_bounds) - (item 2 of tmp_bounds) - yohaku
				set frame_y to (item 3 of tmp_bounds) - (item 1 of tmp_bounds) - yohaku
			end tell
			set my_image to object reference of item 1 of all graphics of my_selection
			tell my_image
				set image_bounds to geometric bounds
				set image_x to ((item 4 of image_bounds) - (item 2 of image_bounds)) * (100 / horizontal scale)
				set image_y to ((item 3 of image_bounds) - (item 1 of image_bounds)) * (100 / vertical scale)
			end tell
			edit original item link of my_image
			my resize_image(frame_x, frame_y, my_resolution, image_x, image_y)
			update item link of my_image
			--fit my_selection given content to frame --内容をフレームに合わせる(今回だけの仕様)
			fit my_selection given proportionally --内容をフレーム内におさめる
			set geometric bounds of my_selection to {y1, x1, y2, x2} --大きさを戻す
			fit my_selection given center content --内容をセンターに
		end repeat
	end tell
end tell

to resize_image(frame_x, frame_y, my_resolution, image_x, image_y)
	tell application "Adobe Photoshop CS"
		if image_x > image_y then
			resize image document 1 width frame_x resolution my_resolution resample method bicubic
			resize image document 1 height frame_y resolution my_resolution resample method bicubic
		end if
		close document 1 saving yes
	end tell
end resize_image