image manipulation: rubber band control?

I’m looking for a way to take a large image and get a portion of it to crop to a preset size. I’ve looked at Image Events and I can see how to do it mathematically (using padding, flipping, and cropping), but I need a user interface that isn’t as clunky as “enter the X,Y coordinates”.

Is there a rubber band control for images? Or can I put a large image in a small window and get a hand cursor to move the image behind it? Or am I asking too much of AppleScript?

You’re certainly asking too much of Image Events. “crop” has no means of specifying where the top left corner of the image will be - the new dimensions are measured from the top left of the original and you can’t keep what’s left, only what’s contained which makes grabbing an arbitrary piece in the middle of a picture a mess of pads, flips and crops to compute. Think about GraphicConverter or something like it where you can grab an arbitrary selection within an image and retain its original resolution.

Adam,

Thanks for responding. I thought about Graphic Converter, but A: I want to see if I can do it and B: I want people to be able to use my app without installing a third party app. Image Events is, as you say, limited but I can work around that if I get the UI right. If I can’t do it inside my app, I may skip the function. It’s way over into the nice-to-have column now anyway.

Re: Crop–Is it from the top left? I thought it selected the middle. Top left makes it easier (yes, using the flip and crop mess, but still!)

I found an app with a custom NSView that does a rubberband selection, and I may see if the author will let me have his custom NSView.

Oops, my bad; Image Events does center the dimensions given on the center of the pic.

I started this some time ago (don’t remember where I got the idea) It requires Xtool version 1.1 (not the more current 2.0). It allows you to select two points (TL, BR) on the image as it is displayed in Preview. I didn’t complete the part about screwing around with pads, flips, and trims to get the image I wanted (and I’m not sure it’s always possible).

-- requires XTool.osax by J-B LeStang: (http://files.macscripter.net/Osax2/Collections/xtool_v11.tgz)

set rect to {}
set saveTarget to path to desktop
-- Get Image size
set thePic to alias ((path to desktop) as text) & "Melmerby at Sunset.jpg"
tell application "Image Events"
	launch
	set tImage to open (thePic as string)
	set S to (dimensions of tImage)
end tell

-- Get location of image on screen in Preview window, corrected for Title bar and Toolbar
tell application "System Events" to tell window 1 of process "Preview"
	set TL to position -- screen coordinates of top left of Preview window
	set BR to size -- coordinates of bottom right of window with respect to top left corner
	tell TL to set item 2 to (item 2) + (item 2 of BR) - (item 2 of S) -- adjusted for window top
end tell
-- Get bounds of rectangle to which to crop image
set W to {"top left", "bottom right"}
repeat with k from 1 to 2 -- get top left and bottom right crop area coordinates
	display dialog "Place the cursor at the " & item k of W & " of" & return & "the area to be selected in your image." & return & return & "Then press 'Enter' without moving the mouse" buttons {"Do Not Click This Button - Press the Enter Key"} default button 1
	set ML to mouse location
	-- check mouse in bounds, store valid point
	repeat with k from 1 to 2
		set pt to (item k of (mouse location)) - (item k of TL)
		if pt < 0 or pt > item k of BR then
			display dialog "Your cursor was not in the image" buttons {"OOPS"} default button 1
			return
		else
			set end of rect to pt
		end if
	end repeat
end repeat
(*
Image Events can only crop an image to the dimensions given centered on the original image; the dimensions given are split evenly about the center.
*)

If things go well, I’ll know if it’s possible soon, unless my wife prevails on me to stop messing with gee-whiz features and get the app shipping. :slight_smile: