This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > PainShop Pro Scripting > May 2007 > Script to read angle from tool options





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Script to read angle from tool options
JoeB

2007-05-08, 6:18 pm

I have a question for those of you who know how to script.

When in Edit Selection mode you can rotate the selection, and the angle
of rotation appears in the Tool Options palette. Can a script be made to
read that angle, and later call the Straighten Tool and insert that
previously read angle info into the Straighten Tool? I can call the
tools, but wouldn't have a clue as to how (if it's possible at all) to
read and pass the angle info from the Deform tool to the Straighten tool.

Regards,

JoeB
Spandex Rutabaga

2007-05-08, 6:18 pm

JoeB wrote:
>
> I have a question for those of you who know how to script.
>
> When in Edit Selection mode you can rotate the selection, and the angle
> of rotation appears in the Tool Options palette.


Do you mean that you apply the Deform tool in Edit Selection
mode and read the rotation of the Deform annotation in the
Tool Options for that tool from the Angle control?

> Can a script be made to
> read that angle, and later call the Straighten Tool and insert that
> previously read angle info into the Straighten Tool?


You can save the setting as preset, which will immortalize the
rotation angle on disk in a file. You can then read it and use
it. This doesn't seem especially convenient. By the way, if you
are thinking of this as a way of simulating PS Crop tool behavior
you might consider rotating the inverted selection so that the
Edit Selection "ruby lith" forms a border around the region to
which you want to crop as a kind of preview of the ultimate crop.

> I can call the
> tools, but wouldn't have a clue as to how (if it's possible at all) to
> read and pass the angle info from the Deform tool to the Straighten tool.
>
> Regards,
>
> JoeB

SuzShook

2007-05-08, 6:18 pm

Spandex Rutabaga wrote:[color=darkred]
> JoeB wrote:
>
> Do you mean that you apply the Deform tool in Edit Selection
> mode and read the rotation of the Deform annotation in the
> Tool Options for that tool from the Angle control?
>
>
> You can save the setting as preset, which will immortalize the
> rotation angle on disk in a file. You can then read it and use
> it. This doesn't seem especially convenient. By the way, if you
> are thinking of this as a way of simulating PS Crop tool behavior
> you might consider rotating the inverted selection so that the
> Edit Selection "ruby lith" forms a border around the region to
> which you want to crop as a kind of preview of the ultimate crop.
>

Hi, JoeB - there is a command called GetToolInfo which returns many of the
settings from the Tool Options palette. However, it does not seem to return
the angle of rotation for either the Deform tool or the Pick tool. It
returns the locations of the 4 corners (handles) of the rectangular rotation
box, and the Pivot Point, but that's about all. There may be a way to
extract the angle of rotation in a script, JoeB, but I can't see how. Suz


JoeB

2007-05-08, 6:18 pm

Spandex Rutabaga <SpRu@agabatur.xednaps> wrote in
news:4640A2D6.89D132DA@agabatur.xednaps:

> JoeB wrote:
>
> Do you mean that you apply the Deform tool in Edit Selection
> mode and read the rotation of the Deform annotation in the
> Tool Options for that tool from the Angle control?
>
>
> You can save the setting as preset, which will immortalize the
> rotation angle on disk in a file. You can then read it and use
> it. This doesn't seem especially convenient. By the way, if you
> are thinking of this as a way of simulating PS Crop tool behavior
> you might consider rotating the inverted selection so that the
> Edit Selection "ruby lith" forms a border around the region to
> which you want to crop as a kind of preview of the ultimate crop.
>


Yes, as I mentioned in my post in the Feature Requests group I was
thinking of a way to simulate the PS Crop tool behaviour. The thought
that came to mind was that one would create a rectangular selection
and go into edit selection mode and adjust the selection as required
and then crop to selection (I already have a script that does that
much, ensuring that the cropped image is on a raster layer with
background transparency). I figured that perhaps the script could
then call the straighten tool, insert the rotation angle info saved
from the Deform Tool, and straighten the image. Then the Crop Tool
could be called with Crop to Opaque selected and the image cropped.
That's the general idea, and there certainly might be a more elegant
way of doing it.

There is one problem I'm aware of, however, and that is with the semi-
transparent pixels around the image caused by rotating in non-90
degree steps. That means there will be one or more semi-transparent
pixels bordering the image, and it's not necessarily the same number
of pixels on any one side. However, I figured I'd worry about that
after I first found out whether or not the angle of rotation could be
saved and used again in the Straighten tool.

The thing is easy enough to record (other than the above mentioned
problem), but what I can't do is have the script remember the rotation
setting in the Deform tool and then insert it into the straighten tool
so that the cropped image gets straightened again.

I'm not sure what you meant about saving a preset, because the preset
would be saved for the Crop tool and can't be accessed by the
Straighten tool. I was hoping (but not very confident) that the
rotation angle in the Deform tool could be somehow saved and then
automatically inserted into the Straighten tool, kind of like you can
manually Ctrl+C the rotation angle from the Deform tool and when you
open the Straighten tool you can paste that setting into it's angle
box.

Regards,

JoeB








>


JoeB

2007-05-08, 6:18 pm

"SuzShook" <suzshook@adelphia.net> wrote in news:463f7ccd$1_1@cnews:

> Spandex Rutabaga wrote:
that[color=darkred]
all)[color=darkred]
>
> Hi, JoeB - there is a command called GetToolInfo which returns many

of
> the settings from the Tool Options palette. However, it does not

seem
> to return the angle of rotation for either the Deform tool or the

Pick
> tool. It returns the locations of the 4 corners (handles) of the
> rectangular rotation box, and the Pivot Point, but that's about all.
> There may be a way to extract the angle of rotation in a script,

JoeB,
> but I can't see how. Suz
>


Thanks for checking that out for me, Suz. I was kind of afraid of
that but thought it worth asking just in case. Once you have rotated
a selection on a raster layer and cropped to the selection you end up
with transparency at different corners of the image, and I can't think
of any other method of making the edges of the image horizontal and
vertical again other than with the Straighten tool. Oh well, it was
just a thought! :-)

Regards,

JoeB
Spandex Rutabaga

2007-05-08, 6:18 pm

JoeB wrote:
>
> "SuzShook" <suzshook@adelphia.net> wrote in news:463f7ccd$1_1@cnews:
>
> that
> all)
> of
> seem
> Pick
> JoeB,
>
> Thanks for checking that out for me, Suz. I was kind of afraid of
> that but thought it worth asking just in case. Once you have rotated
> a selection on a raster layer and cropped to the selection you end up
> with transparency at different corners of the image, and I can't think
> of any other method of making the edges of the image horizontal and
> vertical again other than with the Straighten tool. Oh well, it was
> just a thought! :-)


You can approach this differently in two ways.

Method 1.
Create a new layer at the top of the layer stack. Set its
opacity to zero. Flood fill it with some solid color and
invoke the Deform tool. (This mumbo jumbo allows the
annotation of the Deform tool to be adjusted without moving
the layers below, just as if it were the hypothetical
improved Crop rectangle.) The position of the Deform tool
annotation defines both the rotation angle and the corners
of the crop box. You can return the coordinates of the
corners of the box as Suz indicates. Once you have these you
can compute the rotation angle which the tool applied by
calculating it from its tangent (given by the coordinates).
Now you can estimate new coordinates by rotating the returned
coordinates by the computed angle. You now have the required
rotation angle and the corners of the Crop tool annotation
that should be used after rotation. Make the layer you want
to rotate active and delete the new layer you created. Do
Image > Rotate to rotate by the required angle. Next invoke
the Crop tool with the new rotated coordinates.

Method 2:
Make a rectangular selection and manipulate it in Edit Selection
mode using the Deform tool. (Watch your step since large
deformations might cause soft edges in the selection because
of interpolation.) Retrieve the coordinates of the corners of
the Deform tool annotations as Suz described. Remove the
selection. Use Image > Rotate to rotate the image by the angle
computed from the corner coordinates using the arc tangent.
Update the coordinates of the corners by rotating them through
the same angle (in the same direction :) and use them in the
Crop tool as before.

I think method 1 is nicer. You can make it more cute with the
following extra steps. After creating the new layer and setting
its opacity to zero, you can make a centered selection half the
size of the image and flood fill that selection. After removing
the selection invoke the Deform tool, which will now snap to
the filled rectangle not to the edges of the canvas as before.
You can use this to control the initial placement of the Deform
tool annotation before you start rotating it or changing its
size.
JoeB

2007-05-08, 6:18 pm

Spandex Rutabaga <SpRu@agabatur.xednaps> wrote in
news:4640E9A1.909B4FB8@agabatur.xednaps:

> JoeB wrote:
@cnews:[color=darkred]
the[color=darkred]
behavior[color=darkred]
crop.[color=darkred]
many[color=darkred]
all.[color=darkred]
rotated[color=darkred]
up[color=darkred]
think[color=darkred]
was[color=darkred]
>
> You can approach this differently in two ways.
>
> Method 1.
> Create a new layer at the top of the layer stack. Set its
> opacity to zero. Flood fill it with some solid color and
> invoke the Deform tool. (This mumbo jumbo allows the
> annotation of the Deform tool to be adjusted without moving
> the layers below, just as if it were the hypothetical
> improved Crop rectangle.) The position of the Deform tool
> annotation defines both the rotation angle and the corners
> of the crop box. You can return the coordinates of the
> corners of the box as Suz indicates. Once you have these you
> can compute the rotation angle which the tool applied by
> calculating it from its tangent (given by the coordinates).
> Now you can estimate new coordinates by rotating the returned
> coordinates by the computed angle. You now have the required
> rotation angle and the corners of the Crop tool annotation
> that should be used after rotation. Make the layer you want
> to rotate active and delete the new layer you created. Do
> Image > Rotate to rotate by the required angle. Next invoke
> the Crop tool with the new rotated coordinates.
>


While I certainly appreciate the reply, I've gotta start out by saying
that math is definitely not my strong suit so I don't have a clue
about any of the calculation stuff, so if you mean I'd have to
calculate it then I'm a goner - besides which I was looking for a
script that would do the work. :-) If you're saying that a script can
be written that will do all of the calculations automatically, I'm
afraid that I'm only good at recording them with some rudimentary
ability to edit thereafter, so also wouldn't have a clue about how to
make a script calculate any of the stuff. To be honest, I couldn't
really follow all of this explanation, even though I did try doing
some of it manually - but of course don't know how to calculate the
math. I could just rotate the Deform tool to, say, 30 degrees on the
flood filled layer and then do the same thing on the underlying layer.
I don't think this is a project I'll get off the ground.

But a comment you made in the Method 2 stuff brings up something I
just asked Tim in a reply in the Feature Requests group. The CS2
method obviously crops a portion of the image and rotates it to a
position different from what it was in the original image. As you
have noted, using the Selection>Edit Selection mode to rotate the
selection rectangle causes soft edges, which is an issue. Does the
Deform Tool not create soft edges upon rotation? It appears that the
Crop tool in CS creates hard edges and also doesn't seem to cause loss
of image sharpness caused by the rotation.

Thanks for your effort in any event. There's just some stuff my mind
doesn't wrap itself around very well.

Regards,

JoeB





> Method 2:
> Make a rectangular selection and manipulate it in Edit Selection
> mode using the Deform tool. (Watch your step since large
> deformations might cause soft edges in the selection because
> of interpolation.) Retrieve the coordinates of the corners of
> the Deform tool annotations as Suz described. Remove the
> selection. Use Image > Rotate to rotate the image by the angle
> computed from the corner coordinates using the arc tangent.
> Update the coordinates of the corners by rotating them through
> the same angle (in the same direction :) and use them in the
> Crop tool as before.
>
> I think method 1 is nicer. You can make it more cute with the
> following extra steps. After creating the new layer and setting
> its opacity to zero, you can make a centered selection half the
> size of the image and flood fill that selection. After removing
> the selection invoke the Deform tool, which will now snap to
> the filled rectangle not to the edges of the canvas as before.
> You can use this to control the initial placement of the Deform
> tool annotation before you start rotating it or changing its
> size.
>


Spandex Rutabaga

2007-05-08, 10:18 pm

JoeB wrote:

> While I certainly appreciate the reply, I've gotta start out by saying
> that math is definitely not my strong suit so I don't have a clue
> about any of the calculation stuff, so if you mean I'd have to
> calculate it then I'm a goner - besides which I was looking for a
> script that would do the work. :-)



If you have a sloping line like this one:
<pre>

B
/
/
/
A

</pre>

and the coordinates at point A are (Xa,Ya) and at B are (Xb,Yb)
and the angle of interest is between the horizontal and the line
from A to B then

tangent(angle) = (Yb - Ya) / (Xb - Xa)

and so the angle you want is arctan[(Yb - Ya) / (Xb - Xa)]. The
arc tangent function computes the inverse of the tangent and is
something that should be present in the Python math library.
You need to add one line of Python to your script, which is the
definition of the script doing the work :)

(The tangent of an angle in a right angled triangle is the ratio
of the side opposite the angle to the side at the angle other
than the hypotenuse. Since the zero of coordinates is at top
left for an image and the Y coordinates increase downwards you
might want to swap Yb and Ya in the above equations.)

> If you're saying that a script can
> be written that will do all of the calculations automatically, I'm
> afraid that I'm only good at recording them with some rudimentary
> ability to edit thereafter, so also wouldn't have a clue about how to
> make a script calculate any of the stuff.


Just look inside some of Joe's, Gary's or Suz's scripts to see
how Python elements are added. They can be typed into a previously
recorded script to extend its capabilities.

> To be honest, I couldn't
> really follow all of this explanation, even though I did try doing
> some of it manually - but of course don't know how to calculate the
> math.


Now you do.

> I could just rotate the Deform tool to, say, 30 degrees on the
> flood filled layer and then do the same thing on the underlying layer.
> I don't think this is a project I'll get off the ground.
>
> But a comment you made in the Method 2 stuff brings up something I
> just asked Tim in a reply in the Feature Requests group. The CS2
> method obviously crops a portion of the image and rotates it to a
> position different from what it was in the original image.


I don't think it "obviously crops a portion of the image and
rotates it". It could very well rotate the image (or at least
enough of the image to span across the edges of the crop box)
and then crop it. Read what I wrote about this in reply to the
other post.
JoeB

2007-05-08, 10:18 pm

Spandex Rutabaga <SpRu@agabatur.xednaps> wrote in
news:4640F913.1769A5C4@agabatur.xednaps:

> JoeB wrote:
>
saying[color=darkred]
>
>
> If you have a sloping line like this one:
> <pre>
>
> B
> /
> /
> /
> A
>
> </pre>
>
> and the coordinates at point A are (Xa,Ya) and at B are (Xb,Yb)
> and the angle of interest is between the horizontal and the line
> from A to B then
>
> tangent(angle) = (Yb - Ya) / (Xb - Xa)
>
> and so the angle you want is arctan[(Yb - Ya) / (Xb - Xa)]. The
> arc tangent function computes the inverse of the tangent and is
> something that should be present in the Python math library.
> You need to add one line of Python to your script, which is the
> definition of the script doing the work :)
>
> (The tangent of an angle in a right angled triangle is the ratio
> of the side opposite the angle to the side at the angle other
> than the hypotenuse. Since the zero of coordinates is at top
> left for an image and the Y coordinates increase downwards you
> might want to swap Yb and Ya in the above equations.)
>
to[color=darkred]
>
> Just look inside some of Joe's, Gary's or Suz's scripts to see
> how Python elements are added. They can be typed into a previously
> recorded script to extend its capabilities.
>
>
> Now you do.
>
layer.[color=darkred]
>
> I don't think it "obviously crops a portion of the image and
> rotates it". It could very well rotate the image (or at least
> enough of the image to span across the edges of the crop box)
> and then crop it. Read what I wrote about this in reply to the
> other post.
>


I've read what you said in the other post in Feature Requests, and
replied and commented (I think I got the drift from both of your
posts). I've saved the info for future use when time (and perhaps a
bit more free brain cells) permit :-) Appreciated all the info - some
of which does definitely indicate my limitations in trying these
things out as a challenge.

Regards,

JoeB
SuzShook

2007-05-08, 10:18 pm



Spandex Rutabaga wrote:
> JoeB wrote:
>
>
>
> If you have a sloping line like this one:
> <pre>
>
> B
> /
> /
> /
> A
>
> </pre>
>
> and the coordinates at point A are (Xa,Ya) and at B are (Xb,Yb)
> and the angle of interest is between the horizontal and the line
> from A to B then
>
> tangent(angle) = (Yb - Ya) / (Xb - Xa)
>
> and so the angle you want is arctan[(Yb - Ya) / (Xb - Xa)]. The
> arc tangent function computes the inverse of the tangent and is
> something that should be present in the Python math library.
> You need to add one line of Python to your script, which is the
> definition of the script doing the work :)
>
> (The tangent of an angle in a right angled triangle is the ratio
> of the side opposite the angle to the side at the angle other
> than the hypotenuse. Since the zero of coordinates is at top
> left for an image and the Y coordinates increase downwards you
> might want to swap Yb and Ya in the above equations.)
>
>
> Just look inside some of Joe's, Gary's or Suz's scripts to see
> how Python elements are added. They can be typed into a previously
> recorded script to extend its capabilities.
>
>
> Now you do.
>
>
> I don't think it "obviously crops a portion of the image and
> rotates it". It could very well rotate the image (or at least
> enough of the image to span across the edges of the crop box)
> and then crop it. Read what I wrote about this in reply to the
> other post.


I just looked at what's returned from the GetToolInfo command again - I'm
not sure what those values are! Though they are called Handle1, Handle2,
Handle3, and Handle4, they don't represent the corners of the bounding box
at all. I'd need to study them a bit more to see what they mean. For
example, I just rotated a selection within a 300x300 image to an angle of
340 degrees (20 degrees from where it was originally). The handle values as
returned by GetToolInfo are (226,355), (62,249), (152,110), and (316,216).
Obviously, those cannot be corner values if the image is only 300x300!
Interestingly enough, those are the same values returned from the command
before the image is rotated, so I don't know what we're dealing with here.
Can't find any doc that explains these values, either. The actual corners
of the bounding box before the rotation are (from top left to bottom left,
going clockwise: (39,61), (226,61), (226,232), and (39,232). I'm getting
ready to leave on vacation right now, so don't have time to put into this -
but if nobody has figured out what the numbers mean, I'll take a look when I
get back (next month!). I'm thinking that to use the tangent ratio to
extrapolate the angle or rotation, using the GetRasterSelectionInfo command
both before and after the rotation would be more likely to give usable
information, providing the pivot point of the Deform box is not changed by
the rotation process. I'd love to work on the math here! But, alas, no
time before vacation!!! Suz


JoeB

2007-05-09, 3:16 am

"SuzShook" <suzshook@adelphia.net> wrote in news:463fdc15$1_1@cnews:

>
>
> Spandex Rutabaga wrote:
a[color=darkred]
to[color=darkred]
the[color=darkred]
>
> I just looked at what's returned from the GetToolInfo command again

-
> I'm not sure what those values are! Though they are called Handle1,
> Handle2, Handle3, and Handle4, they don't represent the corners of

the
> bounding box at all. I'd need to study them a bit more to see what
> they mean. For example, I just rotated a selection within a 300x300
> image to an angle of 340 degrees (20 degrees from where it was
> originally). The handle values as returned by GetToolInfo are
> (226,355), (62,249), (152,110), and (316,216). Obviously, those

cannot
> be corner values if the image is only 300x300! Interestingly enough,
> those are the same values returned from the command before the image
> is rotated, so I don't know what we're dealing with here. Can't find
> any doc that explains these values, either. The actual corners of

the
> bounding box before the rotation are (from top left to bottom left,
> going clockwise: (39,61), (226,61), (226,232), and (39,232). I'm
> getting ready to leave on vacation right now, so don't have time to
> put into this - but if nobody has figured out what the numbers mean,
> I'll take a look when I get back (next month!). I'm thinking that

to
> use the tangent ratio to extrapolate the angle or rotation, using

the
> GetRasterSelectionInfo command both before and after the rotation
> would be more likely to give usable information, providing the pivot
> point of the Deform box is not changed by the rotation process. I'd
> love to work on the math here! But, alas, no time before

vacation!!!
> Suz


I'm just guessing, but could the handle values be degrees of relative
position of the handles (just like the angle of rotation is in degrees
of rotation) and not be pixel positions? I'm sure SR will get back
with the real info.

In the meantime, enjoy your holiday!!

Regards,

JoeB
SuzShook

2007-05-09, 6:21 pm



JoeB wrote:
> "SuzShook" <suzshook@adelphia.net> wrote in news:463fdc15$1_1@cnews:
>
>
> I'm just guessing, but could the handle values be degrees of relative
> position of the handles (just like the angle of rotation is in degrees
> of rotation) and not be pixel positions? I'm sure SR will get back
> with the real info.
>
> In the meantime, enjoy your holiday!!
>
> Regards,
>
> JoeB


I agree, Joe - those values must have something to do with angles, but have
not had the time to really look at them. A cursory look sees no
relationship with what shows on the Tool Options palette, but I just may be
missing it. Am actually looking forward to Spandex hopping (rolling???)
back into the conversation! Suz


aaaa

2007-05-10, 6:20 pm

SuzShook wrote:
> JoeB wrote:
snip[color=darkred]
snip[color=darkred]
>
> I agree, Joe - those values must have something to do with angles,

but have
> not had the time to really look at them. A cursory look sees no
> relationship with what shows on the Tool Options palette, but I just

may be
> missing it. Am actually looking forward to Spandex hopping (rolling???)
> back into the conversation! Suz
>
>

If I can chip in with my 20 pounds worth, the interpretation of the
figures is I think:

Handle1= top left of bounding box before deformation
Handle3= bottom right of bounding box before deformation

Handle2=where the top left of the bounding box should go to after
deformation
Handle4=where the bottom right of the bounding box should go to after
deformation

If the bounding box is sufficiently large then after deformation the
bounding box vertices may end up outside the frame of the original
image. Handle2 and Handle3 may have negative values or values greater
than the size of the image because they refer to a point to the left or
above (negative) or to the right or below (greater) the original image.

If the deformation is a simple rotation then ordinary high school
mathematic(s) can solve for the angle. I believe SR has provided some
clues to that.

If free, shear or perspective deformations are involved then it's a bit
more complicated but may still be solvable for angle.

I found all that after a couple of test deformations and looking at the
recorded scripts.

Don't jump on me too heavily should the above prove to be nonsense

AM
>

Spandex Rutabaga

2007-05-10, 6:20 pm

SuzShook wrote:

> The handle values as
> returned by GetToolInfo are (226,355), (62,249), (152,110), and (316,216).
> Obviously, those cannot be corner values if the image is only 300x300!


There is no reason the handle coordinates can't lie outside
the canvas. Open an image, promote its background layer, invoke
the Deform tool, and rotate by some arbitrary amount. Every
handle will be outside the canvas after rotation.

I can't find any documentation about GetToolInfo but I assume
it is using/returning the same handle values that are saved to a
preset or other script. It's something you might want to check
though when you have time.
Spandex Rutabaga

2007-05-10, 6:20 pm

aaaa wrote:

> If I can chip in with my 20 pounds worth,


Ah, a high-value poster I see :) My advice is only worth 20 cents
and the dollar is weak against the pound :)

> the interpretation of the
> figures is I think:
>
> Handle1= top left of bounding box before deformation
> Handle3= bottom right of bounding box before deformation
>
> Handle2=where the top left of the bounding box should go to after
> deformation
> Handle4=where the bottom right of the bounding box should go to after
> deformation


I'm not sure you are correct. It seems to me that the handles
work as in the attached image. However, your post prompted me
as to what to look for so I thank you.

> If the bounding box is sufficiently large then after deformation the
> bounding box vertices may end up outside the frame of the original
> image. Handle2 and Handle3 may have negative values or values greater
> than the size of the image because they refer to a point to the left or
> above (negative) or to the right or below (greater) the original image.


Any handle coordinate value may lie outside the canvas. For
example, if we change the size of the yellow square in the
attached image from 100 x 100 pixels to 200 x 200 pixels (i.e.
to exactly fill the canvas) we get the following.

Initial handle values:
Handle1 (0,200)
Handle2 (0,0)
Handle3 (200,0)
Handle4 (200,200)

After 45 degree clockwise rotation:
Handle1 (-41.4214,100)
Handle2 (100,-41.4214)
Handle3 (241.421,100)
Handle4 (100,241.421)

That's exactly what one would expect for the handle-to-coordinate
mapping described in the example image I attached.

> If the deformation is a simple rotation then ordinary high school
> mathematic(s) can solve for the angle.


Heh, heh! Apparently you have better high schools in the UK than
in the US :) Though from what I have read, standards seem to be
falling in the UK and exam grades are being inflated.

> If free, shear or perspective deformations are involved then it's a bit
> more complicated but may still be solvable for angle.


I think this is why four handle positions are stored even though
one would suffice to define a rotation angle for a rigid rectangle
(along with an assumed initial coordinate). I believe all four
are needed so as to be able to construct the transformation matrix
for arbitrary combinations of scaling, rotation, shear and
perspective. Otherwise there are more unknowns than equations to
solve for them.
FilmPhoto

2007-05-11, 3:24 am


If someone can post some code that reads from the GetToolInfo for the deform
I'll have a go at building the script.

- Simon
www.Justkiss.com






"Spandex Rutabaga" <SpRu@agabatur.xednaps> wrote in message
news:464369FF.519032F2@agabatur.xednaps...
> aaaa wrote:
>
>
> Ah, a high-value poster I see :) My advice is only worth 20 cents
> and the dollar is weak against the pound :)
>
>
> I'm not sure you are correct. It seems to me that the handles
> work as in the attached image. However, your post prompted me
> as to what to look for so I thank you.
>
>
> Any handle coordinate value may lie outside the canvas. For
> example, if we change the size of the yellow square in the
> attached image from 100 x 100 pixels to 200 x 200 pixels (i.e.
> to exactly fill the canvas) we get the following.
>
> Initial handle values:
> Handle1 (0,200)
> Handle2 (0,0)
> Handle3 (200,0)
> Handle4 (200,200)
>
> After 45 degree clockwise rotation:
> Handle1 (-41.4214,100)
> Handle2 (100,-41.4214)
> Handle3 (241.421,100)
> Handle4 (100,241.421)
>
> That's exactly what one would expect for the handle-to-coordinate
> mapping described in the example image I attached.
>
>
> Heh, heh! Apparently you have better high schools in the UK than
> in the US :) Though from what I have read, standards seem to be
> falling in the UK and exam grades are being inflated.
>
>
> I think this is why four handle positions are stored even though
> one would suffice to define a rotation angle for a rigid rectangle
> (along with an assumed initial coordinate). I believe all four
> are needed so as to be able to construct the transformation matrix
> for arbitrary combinations of scaling, rotation, shear and
> perspective. Otherwise there are more unknowns than equations to
> solve for them.



JoeB

2007-05-11, 6:18 pm

"FilmPhoto" <sqw@filmphoto.co.uk> wrote in news:4642b8bb$1_3@cnews:

>
> If someone can post some code that reads from the GetToolInfo for

the
> deform I'll have a go at building the script.
>
> - Simon
> www.Justkiss.com
>


I don't understand much of the stuff I read about writing a script.
However, Suz's zipped download of code snippets for extracting tool
info for text, tubes and shapes includes Quick Guide instructions, and
I suspect that for those who understand scripting (and from her
comments in the instructions) that a scripter would know how to modify
it to get tool info from different fields of the tool ooptions palette
for most tools. If you don't have it and would like to look at it,
you can get it from her site here:

http://suzshook.topcities.com/8scri...GetToolInfo.htm

Regards,

JoeB




>
> "Spandex Rutabaga" <SpRu@agabatur.xednaps> wrote in message
> news:464369FF.519032F2@agabatur.xednaps...
the[color=darkred]
to[color=darkred]
the[color=darkred]
a[color=darkred]
>
>
>


Willy

2007-05-11, 6:18 pm

Is this what you want?
#################

from JascApp import *

def ScriptProperties():
return {
'Author': u'',
'Copyright': u'',
'Description': u'Get tool information from Tool Options palette
using GetToolInfo function created by Gary Barton',
'Host': u'',
'Host Version': u''
}

def Do(Environment):


def GetToolInfo (tool):

### briefly swap tools to force PSP to remember current tool
settings
oldTool = App.Do(Environment, 'SelectTool', {'Tool': 'Pan'})

### get tool settings
info = App.Do(Environment, 'GetCommandInfo', {
'TargetCmd': tool,
'ParamInfo': App.Constants.ParamInfo.LastUsed})

### return info
return info[info['Library'] + '\' + info['Name']]

###
### End of GetToolInfo Function

ToolInfo = GetToolInfo('RasterDeform')
print 'Handle1: ',ToolInfo['Handle1']
print 'Handle2: ',ToolInfo['Handle2']
print 'Handle3: ',ToolInfo['Handle3']
print 'Handle4: ',ToolInfo['Handle4']

############
W


"FilmPhoto" <sqw@filmphoto.co.uk> wrote in message
news:4642b8bb$1_3@cnews...
>
> If someone can post some code that reads from the GetToolInfo for the
> deform I'll have a go at building the script.
>
> - Simon
> www.Justkiss.com
>
>
>
>
>
>
> "Spandex Rutabaga" <SpRu@agabatur.xednaps> wrote in message
> news:464369FF.519032F2@agabatur.xednaps...
>
>



JoeB

2007-05-12, 6:18 pm

"Willy" <willy@hotmail.com> wrote in news:46435c31$1_3@cnews:

> Is this what you want?
> #################
>
> from JascApp import *
>
> def ScriptProperties():
> return {
> 'Author': u'',
> 'Copyright': u'',
> 'Description': u'Get tool information from Tool Options
> palette
> using GetToolInfo function created by Gary Barton',
> 'Host': u'',
> 'Host Version': u''
> }
>
> def Do(Environment):
>
>
> def GetToolInfo (tool):
>
> ### briefly swap tools to force PSP to remember current tool
> settings
> oldTool = App.Do(Environment, 'SelectTool', {'Tool': 'Pan'})
>
> ### get tool settings
> info = App.Do(Environment, 'GetCommandInfo', {
> 'TargetCmd': tool,
> 'ParamInfo': App.Constants.ParamInfo.LastUsed})
>
> ### return info
> return info[info['Library'] + '\' + info['Name']]
>
> ###
> ### End of GetToolInfo Function
>
> ToolInfo = GetToolInfo('RasterDeform')
> print 'Handle1: ',ToolInfo['Handle1']
> print 'Handle2: ',ToolInfo['Handle2']
> print 'Handle3: ',ToolInfo['Handle3']
> print 'Handle4: ',ToolInfo['Handle4']
>
> ############
> W
>



I hope Simon sees this and can do something with it. It would be
interesting to see if this can be made to work, between this code and
what SR said about what has to be done.

Regards,

JoeB

Willy

2007-05-12, 6:18 pm

I haven't followed this thread that close. Maybe I need to read it in a
little more detail to find out exactly what is being tried. If you want to
see all the items returned by the GetToolInfo call you can add a line
print ToolInfo
to the code I posted.
W
"JoeB" <mymail@myserver.com> wrote in message
news:Xns992E69C4D7A36JoeB@216.191.232.194...
> "Willy" <willy@hotmail.com> wrote in news:46435c31$1_3@cnews:
>
>
>
> I hope Simon sees this and can do something with it. It would be
> interesting to see if this can be made to work, between this code and
> what SR said about what has to be done.
>
> Regards,
>
> JoeB
>



JoeB

2007-05-12, 6:18 pm

"Willy" <willy@hotmail.com> wrote in news:4644a266$1_2@cnews:

> I haven't followed this thread that close. Maybe I need to read it

in
> a little more detail to find out exactly what is being tried. If you
> want to see all the items returned by the GetToolInfo call you can

add
> a line
> print ToolInfo
> to the code I posted.
> W


Willy, if you want to get a real background on this, you should start
in the Features Request group, the thread called CS3 Features,
starting with a post by Film Photo (that's Simon) on April 23rd.
Briefly, he wanted a tool in PSP that works like the Crop tool in CS3,
where you call the crop tool and can rotate as well as resize the crop
box and, when applied, it actually creates a cropped image that is
properly vertical and horizontal instead of cropping only to the
bounding box (the latter is what PSP does, which leaves bg color or
transparency around the edges of the image.

The matter then moved to the Scripting group because of a thought I
had about using Edit Selection to rotate a selection, taking the angle
of rotation from the Deform tool when in Edit Selection mode, then
cropping to selection. Then, after the crop, calling the Straighten
tool, inserting that angle of rotation from the Deform tool, and
straightening the image again and selecting and cropping out the
extraneous stuff outside of the image. However, because the original
rotation is done by selection and is less than 90 degrees there is a
feathered edge to the resulting image. Spandex, in this thread,
pointed out a method that is too complicated for me to work with but
that requires getting the handle info from the deform tool from a
temporary layer and subsequently rotating the whole original image,
then invoking the crop tool and calculating the inverse of the
rotation and then doing a crop with the crop tool (at least that's the
gist as I partially understood the thing). That way you don't get
feathered edges.

So if you start with the Film Photo's April 23 post in Feature
Requests, then read through this thread, you'll get the whole picture
and the detailed suggestion from SR.

By the way, I took your code snippet and at first it didn't run.
Apparently when I pasted it in Notepad a few of the text line wrapped
incorrectly, line 7 then line 18 I believe. Anyway, once I got that
sorted the script runs and, after adding the print Toolinfo line I
could see the info that was returned. I only mention this in case
Simon has the same issue trying to use your code snippet.

Regards,

JoeB
FilmPhoto

2007-05-13, 6:18 am

>
> I hope Simon sees this and can do something with it. It would be
> interesting to see if this can be made to work, between this code and
> what SR said about what has to be done.
>
> Regards,
>
> JoeB
>



Hi, yes got this, thanks Willy, I now understand what goes on with tool
info.

I'll start work on the maths next.

BUt, I get odd results from toolinfo, it doesn't seem to want to give me the
current deform, only the last deform.

At the moment i'm calling the routine twice and that seems to work - but am
I missing something?


- Simon
www.JustKiss.com


Willy

2007-05-13, 6:18 pm


"FilmPhoto" <sqw@filmphoto.co.uk> wrote in message
news:4645838c$1_1@cnews...
>
>
> Hi, yes got this, thanks Willy, I now understand what goes on with tool
> info.
>
> I'll start work on the maths next.
>
> BUt, I get odd results from toolinfo, it doesn't seem to want to give me
> the current deform, only the last deform.
>
> At the moment i'm calling the routine twice and that seems to work - but
> am I missing something?
>


I am not sure what you mean by current deform. The function Gary Barton
wrote should force the tool to save in the registry the last settings.
W


FilmPhoto

2007-05-13, 6:18 pm

underprocessable
JoeB

2007-05-13, 6:18 pm

"FilmPhoto" <sqw@filmphoto.co.uk> wrote in news:46461afd_1@cnews:

>
> OK, try this.
>
> Copy script to scripts-restricted.
>
> Run it once to give a 4 x 6 crop box you can position with the Pick
> tool.
>
> Then, run it again to actually do the straighten and crop.
>
> Thanks to Willy, Gary Barton, JoeB, Suze Shook from who I've nicked
> various bits and pieces.
>
> - Simon


Congratulations! It works, except for one thing. You've used the Pick
tool, which v.8 and 9 don't have. I had to change all references from
Pick to RasterDeform. I think you need a GetVersionInfo to determine
whether the tool will be Pick or Rasterdeform.

Also, don't forget to add Spandex to your thanks. It was she, as I
recall, who suggested using the handle info to calculate the angle of
rotation as well as rotating the image first and cropping afterwards.

Regards,

JoeB
JoeB

2007-05-13, 10:17 pm

"FilmPhoto" <sqw@filmphoto.co.uk> wrote in news:46461afd_1@cnews:

>
> OK, try this.
>
> Copy script to scripts-restricted.
>
> Run it once to give a 4 x 6 crop box you can position with the Pick
> tool.
>
> Then, run it again to actually do the straighten and crop.
>
> Thanks to Willy, Gary Barton, JoeB, Suze Shook from who I've nicked
> various bits and pieces.
>
> - Simon
> www.JustKiss.com


Simon, after playing with the script for a bit, I have another
suggestion and would be glad to hear your comments on it.

The script presently defaults to a 4x6 crop, and that makes sense when
one thinks that the average person will want to crop to a ratio that
will be printed as a standard print. However, I found that it caused
me some confusion for a time, and here's why (and I hope I explain it
OK).

Let's assume the image I'm going to run the script on is in landscape
mode. The default size of the initial deform box is a rectangle (as
opposed to a square). Now assume that what I want to crop and
straighten is a portion of the image that I want to end up being in
portrait format (i.e., when cropped it will be taller than it is wide,
unlike the image from which I'm making my crop). My first instinct
when I was playing with the script was to grab the rotation handle and
rotate the rectangular box so that, while at the general angle I
wanted, I used its default longer side as the orientation (so that I
have rotated what started as a landscape format selection into a
somewhat portrait format selection). Then I would do the resizing
using the border handles. Then I would run the script again for the
crop. As a result, the new image came out with the part I wanted
vertical actually being horizontal.

I think I did the rotate thing first because my brain automatically
decided that the selection had a portrait option available so I used
it first by rotation before doing the resizing. But this results in
the script returning handle info that isn't what I was expecting,
because I either rotated the rectangular selection past 90 degrees to
the right or (if using the bottom of the selection) rotated in the
wrong direction.

I'm wondering ('cause it works in my brain for what that's worth) if
it might be better to have the original selection box square. That
wouldn't trigger an automatic impulse to rotate the selection box to
the approximate angle one was trying to achieve. It would, I think,
trigger a response to either resize the shape of the selection closer
to the desired size and shape first and then rotate, or if rotating
first it would at least cause one to only rotate to close to the
desired angle (which would not cause one to rotate past 90 degrees)
then resize, which should return the correct numbers to rotate the
image properly for cropping.

That's just a thought I had. If I'm missing something I'm only too
glad to get the feedback.

Regards,

JoeB

JoeB

2007-05-13, 10:17 pm

And if I can be forgiven for adding this bit extra to my post to which
I'm replying, perhaps if you feel that the square selection might be a
better place to start for the average individual, you might consider
both centering the square and making the default selection 45% of the
shortest side of the image so that if they do rotate first they won't
lose any handles outside of the image.

Regards,

JoeB

JoeB <mymail@myserver.com> wrote in news:Xns992FAE728A2F2JoeB@
216.191.232.194:

> "FilmPhoto" <sqw@filmphoto.co.uk> wrote in news:46461afd_1@cnews:
>
>
> Simon, after playing with the script for a bit, I have another
> suggestion and would be glad to hear your comments on it.
>
> The script presently defaults to a 4x6 crop, and that makes sense

when
> one thinks that the average person will want to crop to a ratio that
> will be printed as a standard print. However, I found that it

caused
> me some confusion for a time, and here's why (and I hope I explain

it
> OK).
>
> Let's assume the image I'm going to run the script on is in

landscape
> mode. The default size of the initial deform box is a rectangle (as
> opposed to a square). Now assume that what I want to crop and
> straighten is a portion of the image that I want to end up being in
> portrait format (i.e., when cropped it will be taller than it is

wide,
> unlike the image from which I'm making my crop). My first instinct
> when I was playing with the script was to grab the rotation handle

and
> rotate the rectangular box so that, while at the general angle I
> wanted, I used its default longer side as the orientation (so that I
> have rotated what started as a landscape format selection into a
> somewhat portrait format selection). Then I would do the resizing
> using the border handles. Then I would run the script again for the
> crop. As a result, the new image came out with the part I wanted
> vertical actually being horizontal.
>
> I think I did the rotate thing first because my brain automatically
> decided that the selection had a portrait option available so I used
> it first by rotation before doing the resizing. But this results in
> the script returning handle info that isn't what I was expecting,
> because I either rotated the rectangular selection past 90 degrees

to
> the right or (if using the bottom of the selection) rotated in the
> wrong direction.
>
> I'm wondering ('cause it works in my brain for what that's worth) if
> it might be better to have the original selection box square. That
> wouldn't trigger an automatic impulse to rotate the selection box to
> the approximate angle one was trying to achieve. It would, I think,
> trigger a response to either resize the shape of the selection

closer
> to the desired size and shape first and then rotate, or if rotating
> first it would at least cause one to only rotate to close to the
> desired angle (which would not cause one to rotate past 90 degrees)
> then resize, which should return the correct numbers to rotate the
> image properly for cropping.
>
> That's just a thought I had. If I'm missing something I'm only too
> glad to get the feedback.
>
> Regards,
>
> JoeB
>
>


FilmPhoto

2007-05-14, 3:21 am

underprocessable
JoeB

2007-05-14, 6:18 pm

"FilmPhoto" <sqw@filmphoto.co.uk> wrote in news:4646afd1$1_1@cnews:

>
> OK, This version asks which standard photographic proportion you

want by
> default.
>
> Of course you can very the proportion once you've started.
>
> It also rotates to the nearest angle, so if you rotate the crop box

from
> portrait to landscape orientation you get a landscape crop
>
> - Simon
> www.JustKiss.com
>



Because the script still uses the Pick tool, it won't run in v.8 or 9.

As with the last one, I changed all instances of Pick to RasterDeform,
but after I do so I get an error at the end of the script (which I
didn't get when I changed the previous script). Here's the contents
of the SOP:


Executing RunScript
Executing EnableOptimizedScriptUndo
Executing ReturnImageInfo
Executing ModifySelection
Executing EditSelection
Executing SelectLayer
Executing SelectTool
Executing ImageInfo

Script 'UTIL-SQW-CropTo4x6_rev1' has completed successfully.
Executing RunScript
Executing EnableOptimizedScriptUndo
Executing ReturnImageInfo
Executing SelectTool
Executing SelectPreviousTool
Executing GetCommandInfo
Executing SelectTool
Executing SelectPreviousTool
Executing GetCommandInfo
------- Command Execution Failed -----------
Command Name: GetCommandInfo
Error Text: A parameter to a command has an invalid value.
Traceback (most recent call last):
File "C:\Documents and Settings\Joe\My Documents\My PSP Files
\Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
199, in Do
DoNextStep(Environment)
File "C:\Documents and Settings\Joe\My Documents\My PSP Files
\Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
250, in DoNextStep
eval(stepList[doStep] + '(Environment)')
File "<string>", line 0, in ?
File "C:\Documents and Settings\Joe\My Documents\My PSP Files
\Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
102, in DoStep2
ToolInfo = GetToolInfo(Environment,'RasterDeformk')
File "C:\Documents and Settings\Joe\My Documents\My PSP Files
\Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
293, in GetToolInfo
info = App.Do(Environment, 'GetCommandInfo', {
JascApp.InvalidParameterValid: Invalid parameter value

Script 'UTIL-SQW-CropTo4x6_rev1' has completed with an error.


Regards,

JoeB
FilmPhoto

2007-05-14, 6:18 pm

My guess is you've lost a quote mark when changing the tool name.

- Simon


"JoeB" <mymail@myserver.com> wrote in message
news:Xns9930687B55EA1JoeB@216.191.232.194...
> "FilmPhoto" <sqw@filmphoto.co.uk> wrote in news:4646afd1$1_1@cnews:
>
> want by
> from
>
>
> Because the script still uses the Pick tool, it won't run in v.8 or 9.
>
> As with the last one, I changed all instances of Pick to RasterDeform,
> but after I do so I get an error at the end of the script (which I
> didn't get when I changed the previous script). Here's the contents
> of the SOP:
>
>
> Executing RunScript
> Executing EnableOptimizedScriptUndo
> Executing ReturnImageInfo
> Executing ModifySelection
> Executing EditSelection
> Executing SelectLayer
> Executing SelectTool
> Executing ImageInfo
>
> Script 'UTIL-SQW-CropTo4x6_rev1' has completed successfully.
> Executing RunScript
> Executing EnableOptimizedScriptUndo
> Executing ReturnImageInfo
> Executing SelectTool
> Executing SelectPreviousTool
> Executing GetCommandInfo
> Executing SelectTool
> Executing SelectPreviousTool
> Executing GetCommandInfo
> ------- Command Execution Failed -----------
> Command Name: GetCommandInfo
> Error Text: A parameter to a command has an invalid value.
> Traceback (most recent call last):
> File "C:\Documents and Settings\Joe\My Documents\My PSP Files
> \Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
> 199, in Do
> DoNextStep(Environment)
> File "C:\Documents and Settings\Joe\My Documents\My PSP Files
> \Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
> 250, in DoNextStep
> eval(stepList[doStep] + '(Environment)')
> File "<string>", line 0, in ?
> File "C:\Documents and Settings\Joe\My Documents\My PSP Files
> \Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
> 102, in DoStep2
> ToolInfo = GetToolInfo(Environment,'RasterDeformk')
> File "C:\Documents and Settings\Joe\My Documents\My PSP Files
> \Scripts-Restricted\Tools\UTIL-SQW-CropTo4x6_rev1.PspScript", line
> 293, in GetToolInfo
> info = App.Do(Environment, 'GetCommandInfo', {
> JascApp.InvalidParameterValid: Invalid parameter value
>
> Script 'UTIL-SQW-CropTo4x6_rev1' has completed with an error.
>
>
> Regards,
>
> JoeB



JoeB

2007-05-14, 6:18 pm

"FilmPhoto" <sqw@filmphoto.co.uk> wrote in news:46473fd9_3@cnews:

> My guess is you've lost a quote mark when changing the tool name.
>
> - Simon
>


Thanks Simon, there was an operator error in replacing the tool name.
It now works great in PSP9! I've added it as a boundscript to my Crop
Tool flyout and it works well, just clicking the icon again to run the
crop part (which is no different than hitting an apply button, so very
convenient).

If you were to add the GetVersionInfo function so it works in all
versions, or if it's easier just make a v.8/9 script, I'd say you
should post it and advise users in all groups that it's available. I
have seen at least a couple of other people over the months ask for
the Photoshop type of crop tool.

Good work!

Regards,

JoeB

[color=darkred]
>
> "JoeB" <mymail@myserver.com> wrote in message
> news:Xns9930687B55EA1JoeB@216.191.232.194...
box[color=darkred]
9.[color=darkred]
RasterDeform,[color=darkred]
contents[color=darkred]
Spandex Rutabaga

2007-05-14, 6:18 pm

JoeB wrote:

> As with the last one, I changed all instances of Pick to RasterDeform,


You changed something to RasterDeformk
JoeB

2007-05-14, 6:18 pm

Spandex Rutabaga <SpRu@agabatur.xednaps> wrote in news:4648A9C3.5883F905
@agabatur.xednaps:

> JoeB wrote:
>
>
> You changed something to RasterDeformk
>


Correct, and I don't think that tool will be available until v.XII gets
released. :-)

Regards,

JoeB
Sponsored Links


Copyright 2003 - 2009 forum4designers.com  Software forum  Computer Hardware reviews