• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Rotate layer between image using anchor position as TOPCENTER

Engaged ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

Hi Everyone,

I have facing problem to finding the (Layer) rotating angel between image document.

The layer needs to center between image document. Is this possible via script or any help much appreciated to solve this

Please find the screen shot for your reference.

This is a source image and second one is final output shows.

Source.JPG    Final.JPG

- yajiv

TOPICS
Actions and scripting

Views

1.5K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Mar 04, 2018 Mar 04, 2018

The best way is to designate two points on the upper vertical boundary of the pixels of the layer and two points on the lower border of the pixels of the layer, for example, using the pen tool. Then it is easy to calculate the angle of rotation so that the points become vertically symmetric after the transformation.

In your simple case, you can set one guide as in the picture and run the script.

a1.png

In a more complex case, you need to set up two guides roughly like in the figure and run the script.

a2.png

Sin

...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

natrev  wrote

Hi Everyone,

I have facing problem to finding the (Layer) rotating angel between image document.

The layer needs to center between image document. Is this possible via script or any help much appreciated to solve this

Please find the screen shot for your reference.

This is a source image and second one is final output shows.

It easy to align a layer to any pixels you want.  What angle are you referring to the screen captures are incomplete and you are zoomed in so much we can not see the images and the layers palette to know the structure of your documents. I would think the image would be the same size in both the documents and the layer be the same angle in both documents if you Placed or pasted one into the other.  Are you trying to rotate some image object to make it more plum the the vertical axis.  If you are you need to identify  the top and bottom point you want vertical. there are no straight edges and the black item you show is not symmetric.  I would not know what  you want to be vertical.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

Hi JJMack,

Thank you so much for your reply.

Here the concern is I need to rotating layer with lock the top center position.

Since if you saw the Fig.1 at Bottom left is closer to the product.

I need to center align (rotate) the product(lock the top center position) between the left and right of document.

for your reference Please the see the Fig.2. The manual angle position is -0.2°.

I need to figure out the angle position.

-yajiv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

natrev  wrote

Hi JJMack,

Thank you so much for your reply.

Here the concern is I need to rotating layer with lock the top center position.

Since if you saw the Fig.1 at Bottom left is closer to the product.

I need to center align (rotate) the product(lock the top center position) between the left and right of document.

for your reference Please the see the Fig.2. The manual angle position is -0.2°.

I need to figure out the angle position.

-yajiv

What is closer to what product? In your top image I see a tall black object that is not symmetric with no straight edge or line  on a transparent background.

In the bottom image I see you have zoomed in so about the bottom third of the object is only visible.  It look like your using free transform and moved the anchor point to the top center of the layer bounds where ever that is. its not visible.  It look like the layer may be the same size and aspect ratio as the document canvas but has been moved a little off canvas on the right side. So the canvas is now clipping part of the object that is off screen. The transform beside moving part of the layer off canvas  has been  rotated -0.15 degree so part of top of the images may also be off canvas. Bicubic  interpolations will be use when the transform is committed.

Final.JPG

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

Wasn't here r-bin​ answer with code to do it? Or I dreamt?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

Kukurykus 

Wasn't here r-bin  answer with code to do it? Or I dreamt?

There was a mistake. Maybe later I'll post it somehow.)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 03, 2018 Mar 03, 2018

Copy link to clipboard

Copied

Hi Kukurykus,

Thank you so much for your reply. I didn't see any code post here..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Mar 04, 2018 Mar 04, 2018

Copy link to clipboard

Copied

The best way is to designate two points on the upper vertical boundary of the pixels of the layer and two points on the lower border of the pixels of the layer, for example, using the pen tool. Then it is easy to calculate the angle of rotation so that the points become vertically symmetric after the transformation.

In your simple case, you can set one guide as in the picture and run the script.

a1.png

In a more complex case, you need to set up two guides roughly like in the figure and run the script.

a2.png

Since the calculation of symmetric points using guides may not be accurate enough for a strong rotation, it is possible that in the second case it will be necessary to run the script twice for a more accurate result.

app.activeDocument.suspendHistory("Straighten","straighten_hor_by_guides()");

function straighten_hor_by_guides()

    {

    try {

        var doc = app.activeDocument;

        var layer = app.activeDocument.activeLayer;

        var g0, g1;

        if (!doc.guides.length) { alert("No guides!"); return; }

        for (var i = 0; i < doc.guides.length; i++)

            {

            if (doc.guides.direction == Direction.HORIZONTAL)

                {

                if (g0 == undefined) g0 = doc.guides;

                else if (g1 == undefined) g1 = doc.guides;

                else { alert("Too many horizontal guides!"); return; }

                }

            }

        if (g0 == undefined && g1 == undefined)

            {

            alert("No horizontal guides!"); return;

            }

        else if (g0 != undefined && g1 == undefined)

            {

            app.preferences.rulerUnits = Units.PIXELS;

            var y0 = Number(layer.bounds[1].value);

            var x0 = Number(layer.bounds[2].value + layer.bounds[0].value)/2;

            var y1 = Number(g0.coordinate.value);

            selection_from_layer();

            select_single_line(y1, true, stringIDToTypeID("intersectWith"));

            try { var x1 = Number(doc.selection.bounds[2].value + doc.selection.bounds[0].value)/2; } catch(e) { alert("Bad guide!"); return; }

            var w = x1 - x0;

            var h = y1 - y0;

            var angle;

            if (h != 0) angle = Math.atan(w/h) * 180.0 / Math.PI;

            doc.selection.deselect();

            if (angle != undefined) rotate(angle, x0, y0);

            }

        else if (g0 != undefined && g1 != undefined)

            {

            app.preferences.rulerUnits = Units.PIXELS;

            var y0 = Number(g0.coordinate.value);

            var y1 = Number(g1.coordinate.value);

            if (y0 > y1) { var tmp = y1; y1 = y0; y0 = tmp; }

            selection_from_layer();

            select_single_line(y0, true, stringIDToTypeID("intersectWith"));

            var x0 = Number(doc.selection.bounds[2].value + doc.selection.bounds[0].value)/2;

           

            selection_from_layer();

            select_single_line(y1, true, stringIDToTypeID("intersectWith"));

            var x1 = Number(doc.selection.bounds[2].value + doc.selection.bounds[0].value)/2;

            var w = x1 - x0;

            var h = y1 - y0;

            var angle;

            if (h != 0) angle = Math.atan(w/h) * 180.0 / Math.PI;

            doc.selection.deselect();

            if (angle != undefined) rotate(angle, x0, y0);

            }

        }

    catch (e) { alert(e) }

    }

function select_single_line(x, h, mode)

    {

    try

        {

        if (mode == undefined) mode = stringIDToTypeID("set");

        var r = new ActionReference();

        r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));

        var d = new ActionDescriptor();

        d.putReference(stringIDToTypeID("target"), r);

        var d1 = new ActionDescriptor();

        d1.putUnitDouble(stringIDToTypeID(h?"top":"left"), stringIDToTypeID("pixelsUnit"), x);

        d.putObject(stringIDToTypeID("to"), stringIDToTypeID(h?"singleRow":"singleColumn"), d1);

        executeAction(mode, d, DialogModes.NO);

        }

    catch (e) { throw(e); }

    }

function rotate(angle, x, y)

    {

    try

        {

        var r = new ActionReference();

        r.putEnumerated(stringIDToTypeID("layer"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

        var d = new ActionDescriptor();

        d.putReference(stringIDToTypeID("target"), r);

        d.putEnumerated(stringIDToTypeID("freeTransformCenterState"), stringIDToTypeID("quadCenterState"), stringIDToTypeID("QCSIndependent"));

        var d2 = new ActionDescriptor();

        d2.putUnitDouble(stringIDToTypeID("horizontal"), stringIDToTypeID("pixelsUnit"), x);

        d2.putUnitDouble(stringIDToTypeID("vertical"),   stringIDToTypeID("pixelsUnit"), y);

        d.putObject(stringIDToTypeID("position"), stringIDToTypeID("point"), d2);

        d.putUnitDouble(stringIDToTypeID("angle"), stringIDToTypeID("angleUnit"), angle);

        d.putEnumerated(stringIDToTypeID("interpolation"), stringIDToTypeID("interpolationType"), stringIDToTypeID("bicubic"));

        executeAction(stringIDToTypeID("transform"), d, DialogModes.NO);

        }

    catch (e) { throw(e); }

    }

function selection_from_layer()

    {

    try

        {

        var r = new ActionReference();

        r.putProperty(stringIDToTypeID("channel"), stringIDToTypeID("selection"));

        var d = new ActionDescriptor();

        d.putReference(stringIDToTypeID("target"), r);

        var r = new ActionReference();

        r.putEnumerated(stringIDToTypeID("channel"), stringIDToTypeID("channel"), stringIDToTypeID("transparencyEnum"));

        d.putReference(stringIDToTypeID("to"), r);

        executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

        }

    catch (e) { throw(e); }

    }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 05, 2018 Mar 05, 2018

Copy link to clipboard

Copied

LATEST

Hi r-bin,

Externally sorry for the delayed response,

This what I exactly needed and Thank you so much for timely help.

Its working like a charm.....

-yajiv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines