Page 1 of 1

Image.Rectangle Crop

Posted: 15 Nov 2021, 15:56
by Morten Lerager
Hi' AA's
(Nothing about Alcoholic)
Trying to make it easy to crop to a known aspect ratio.
I can make a crop by the Image.crop (x1,y1,x2,y2)
But that's very "hard coded" (Inflexible)
Then we have the Image.Rectangle but as I read it, it's only for returning size, not for setting.
I want a macro to act like :
Make a Rectangle Selection
Press ^R
Read the coordinate and change them according to aspect ratio.
Then move the selection as normal ^ mouse
And then do a Crop.

So how to do that :?:

Re: Image.Rectangle Crop

Posted: 16 Nov 2021, 02:45
by Iver
Hi Morten, open an image you want to crop then drag a rectangle the size and position you want. Next open define Macro and then use the slider to find Crop. Double click crop and name the macro. When you run that macro it will crop the image that is open or you can load the images you want cropped and they will all be cropped.

Re: Image.Rectangle Crop

Posted: 16 Nov 2021, 04:03
by fabdev
Hi, may you explain the pass:
"Read the coordinate and change them according to aspect ratio" ?
What is the goal of the processing? Maybe there's a different way to do that.
Fabio.

Re: Image.Rectangle Crop

Posted: 16 Nov 2021, 17:05
by Morten Lerager
Thank's Fabio
The goal is to crop in etc 3:2 format.
As I understand the crop as it is, I'll have to do the calc. every time. The macro is for simulate crop as we know it in PS or Gimp. Make a selection with giving aspect ration.

@Iver that way will only make the same crop every time.
Same as the Image.crop x1,x2,y1,y2

Re: Image.Rectangle Crop

Posted: 17 Nov 2021, 02:07
by fabdev
OK.
It's not possible to select a rectangle via scripts, but since usually a selection is centered around an object, this script could solve:
Select a point on the subject then:

Code: Select all

sizeX = 300
sizeY = 200
if Image.Points.Count <> 1 then
   Message("Please select a point")
   end
end if
cx = Image.GetPointX
cy = Image.GetPointY
x1 = cx - sizeX / 2
y1 = cy - sizeY / 2
x2 = x1 + sizeX - 1
y2 = y1 + sizeY - 1
Image.PrepareUndo
Image.Crop(x1, y1, x2, y2)
This could be modified to work on selected rectangles too, where cx, cy, and size are calculated from the active rectangle.

Re: Image.Rectangle Crop

Posted: 17 Nov 2021, 18:45
by Morten Lerager
Thank's Fabio
I look into it and return with a solution.

Re: Image.Rectangle Crop

Posted: 28 Nov 2021, 15:25
by Morten Lerager
Hi'
I came up with this solution.
Not so smooth as i was aimed for. But it' works
The Crop will be in a Aspect Ratio of 3:2
Preselect a rectangle. The hight is used to calculate the crop width

' *** Aspect Ratio ***
' *** AstroArt 8 ***
' *** 28:11:21 Morten Lerager ***
' Make rectangle selection
' The Hight will be used for Calc. the size.
' So the width is Only for only for determination the center
AR=1.5 '=Aspect Ratio 3:2
x1 = Image.Rectangle.X1
y1 = Image.Rectangle.Y1
x2 = Image.Rectangle.X2
y2 = Image.Rectangle.Y2
if x1 = x2 then
print "Select rectangle with a Height to Crop before RUN"
end
end if
height=(y2-y1)
IF frac(height/2) = 0.5 Then
y2=y2+1
height=height+1
endif
HW=int(height*1.5/2)
xcen=(x2-x1)/2+x1
x1=xcen-HW
x2=xcen+HW

If x1<0 then
Print "X<0 out of border"
END
end if
If x2>Image.Width then
Print "X> Image Width out of border"
END
end if

Image.Points.Add(x1,y1)
Image.Points.Add(x2,y1)
Image.Points.Add(x2,y2)
Image.Points.Add(x1,y2)
Input "Do yot want to Crop at these four points Y/N ?", answer
IF answer <> "Y" and answer <> "y" then
Image.Points.Clear
Print "STOPPED"
END
end if
Image.Points.Clear
Image.PrepareUndo
Image.crop (x1,y1,x2,y2)
Image.Update

Re: Image.Rectangle Crop

Posted: 30 Nov 2021, 14:07
by fabdev
Thanks Morten, I confirm that in AA8 Service pack 1 there will be a script command to select rectangles.
Fabio.

Re: Image.Rectangle Crop

Posted: 30 Nov 2021, 18:32
by Morten Lerager
Oh, thats greeat news Fabio, thank you.
i will be looking forward to it.