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

Positioning Layer Relative to Guides

New Here ,
Feb 27, 2018 Feb 27, 2018

I have two files I will call file a and file b.  File a is a template, it is 1335x5400 pixels, single layer, and has a single horizontal guide at exactly 1300 pixels from the top.   File b is variable size, single layer, and can have a single horizontal guide anywhere.  I need to take File b, resize it, and copy it into File a, then move it to a specific location.  The location differs depending on whether or not there is a guide in File b.

What I am currently doing is opening File a, then opening File b, resizing the image, duplicating the active layer to File a, switching to File a, repositioning the layer to the desired location, exporting the resulting image,  and then closing both files.  This works great.  However, I have no clue as to how I could possibly duplicate the guides from File b to File a (I am not really sure I would need to do that either) and how to align the layer using this guide.

I would much appreciate it if someone could post example code.  Thank you very much in advance.

TOPICS
Actions and scripting
1.7K
Translate
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 , Feb 28, 2018 Feb 28, 2018

Is this suitable?

app.preferences.rulerUnits = Units.PIXELS;

var doc_a; 

var doc_b;

try { doc_a = activeDocument; } catch(e) {} // assume that doc_a is an active document or define doc_a and doc_b yourself

for (var i = 0; i < documents.length; i++) if (documents.id != doc_a.id) { doc_b = documents; break; }

if (doc_a == undefined) alert("Active document is missing")

else if (doc_b == undefined) alert("The second document is missing")

else

    {

    var offset_a;

    var offset_b;

    activeDocument = doc_

...
Translate
Adobe
Community Expert ,
Feb 27, 2018 Feb 27, 2018

Guide lines are a Photoshop UI thing not actally part of your image. Some file formats can save all sorts of Photoshop information like layers selections and guides example PSD and PSD files.  You will not be able to save things like Photoshop guideline information in file formats like jpeg, png and gif as far as I know.  If you need to save guide lines  save your document into a Photoshop file format like PSD or PSB.  Tiff also support layers I do not know about saving guide lines..You can set guides anywhere you want to in a Photoshop script.

Why are you using guideline to begin with in your templates and other files? Why are they needed?

You seen to know the template is 1335x5400 pixels, single layer, and  you want to align something 1300 pixels from  the top  top. Why do you need a guide there?

JJMack
Translate
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
Advocate ,
Feb 27, 2018 Feb 27, 2018

JPG & TIF support guides

Translate
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 ,
Feb 27, 2018 Feb 27, 2018

I wrote I did not know I never save guideline in jpeg. I wrote tiff support Photoshop things like layers.  What I asked is why do they need guides if they are scripting the process know the image size pixels wide and high  and know they want to align a new image layer some size 1300 px down from the top? They can set guides anywhere they want to in a script.  I wanted to know what for?

JJMack
Translate
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
New Here ,
Feb 27, 2018 Feb 27, 2018

Thank you for your replies.  Perhaps I was not clear with what I need to accomplish.  The guides are only important because they indicate where the two files should be 'joined' but there is no requirement to save or preserve the guides at the end of the process.

Consider the following example, I start with 2 files - File A and File B. I need to open File B, resize it,  copy its only layer to File A, and then move the copied layer to a certain position.  tI have thousands of distinct File B files, some of which have a guide as illustrated below.  The guide can be anywhere in File B but it will always be horizontal.

File A also has a guide.  That guide is located at 1300px from the top of the file as illustrated below.  The objective is to place File B in File A in such a way so that their guides would 'match' as illustrated below.  

Dupe.png

The guides themselves are unimportant to the end result.  It doesn't matter to me if they cannot be preserved or saved with the file. The position of File B is what is important here.

I currently duplicate File B's active layer into File A, and then use the activeLayer.translate method to move the layer into position.  This works great but I just don't know how to determine where to move the layer if I have to make that determination based on where the guide was located at in File B.   This is what I need help with.  Does this make better sense?

Translate
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 ,
Feb 28, 2018 Feb 28, 2018

The problem I have with what you write is I have no idea of what you mean by resize document B or what effect it will have on the document horizontally guide.  If you are increasing or decreasing the number of pixels  so it will be the same number or pixels some object in document A has.  And if the single layer in document B is a pixel raster layer why  the resample image would match any image in Document A.   I would think the Image in document B is not being stitched to an image in document A.   Its the resize and the importance of document B  guide if document B is being resized.  Do not know what the resize criteria is.  The diagram does not even show anything about the resize mentioned in the process description. Or even show if something in document a is being matched.  I have no idea as to what this resize and positioning is all about

JJMack
Translate
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
New Here ,
Feb 28, 2018 Feb 28, 2018

If you think about it, resizing the document in any direction, proportional or not, is irrelevant to the end result.  All that is needed here is to place the two images so that pixel y in one of the images is located at exactly 1300 pixels from the top of the other image.  Really, it doesn't matter if you resize or not, in the end, the result is the same relatively speaking.

Is there a way to read the position of the guides?  If so, can anyone provide an example? I am pretty sure that if I know how to read the position of the guides, I can figure out the rest quickly. 

Translate
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 ,
Feb 28, 2018 Feb 28, 2018

Is this suitable?

app.preferences.rulerUnits = Units.PIXELS;

var doc_a; 

var doc_b;

try { doc_a = activeDocument; } catch(e) {} // assume that doc_a is an active document or define doc_a and doc_b yourself

for (var i = 0; i < documents.length; i++) if (documents.id != doc_a.id) { doc_b = documents; break; }

if (doc_a == undefined) alert("Active document is missing")

else if (doc_b == undefined) alert("The second document is missing")

else

    {

    var offset_a;

    var offset_b;

    activeDocument = doc_b;

    try {

    if (doc_b.guides[0].direction == Direction.HORIZONTAL)

        offset_a = doc_b.guides[0].coordinate;

    }

    catch (e) {}   

    activeDocument = doc_a;

    try {

    if (doc_a.guides[0].direction == Direction.HORIZONTAL)

        offset_b = doc_a.activeLayer.bounds[1] - doc_a.guides[0].coordinate;

    }

    catch (e) {}   

    // duplicate layer from doc_b to doc_a

    activeDocument = doc_b;

    doc_b.activeLayer.duplicate(doc_a.activeLayer, ElementPlacement.PLACEBEFORE);

    // translate layer to position

    activeDocument = doc_a;

    if (offset_a != undefined && offset_b != undefined)

        doc_a.activeLayer.translate(0, doc_a.activeLayer.bounds[1] - offset_b - offset_a)

    else

        alert("Position is undefined!");

    }

P.S. was edited

Translate
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 ,
Feb 28, 2018 Feb 28, 2018

I do not see any resize in that script just positioning.

JJMack
Translate
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 ,
Feb 28, 2018 Feb 28, 2018

JJMack

I do not see any resize in that script just positioning.

The criteria for resizing have not been described. But to make it is not difficult.

Translate
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 ,
Feb 28, 2018 Feb 28, 2018
LATEST

That has been my point from the beginning. the positioning is not the hard part.  The resizes is.

JJMack
Translate
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 ,
Feb 28, 2018 Feb 28, 2018

mrforged  wrote

If you think about it, resizing the document in any direction, proportional or not, is irrelevant to the end result.  All that is needed here is to place the two images so that pixel y in one of the images is located at exactly 1300 pixels from the top of the other image.  Really, it doesn't matter if you resize or not, in the end, the result is the same relatively speaking.

Is there a way to read the position of the guides?  If so, can anyone provide an example? I am pretty sure that if I know how to read the position of the guides, I can figure out the rest quickly. 

If I resize  a document height by changing the canvas size I either add empty canvas or crop the image the change can to either top or bottom side or both sides came be changed the same or different amount, the horizontal guide line relative position to the canvas will change.    If the width is change by changing canvas size the relative position will not change.

If instead you change the document content to some new height or width you have to distort the image with content aware resize or  interpolation distortion  to fill the image new aspect ratio.  You never describe the resize you are performing.

how can resizing be irrelevant to the end result if it is irrelevant why do it at all.

JJMack
Translate
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 ,
Feb 28, 2018 Feb 28, 2018

mrforged  wrote

I have two files I will call file a and file b.  File a is a template, it is 1335x5400 pixels, single layer, and has a single horizontal guide at exactly 1300 pixels from the top.  

File b is variable size, single layer, and can have a single horizontal guide anywhere. 

I need to take File b, resize it, and copy it into File a,

then move it to a specific location.  The location differs depending on whether or not there is a guide in File b.

We know a lot about file A the number of pixels its canvas width and height  is and a horizontal pixel row 1300 pixels down from its 5400px height.   We do not know the  document resolution setting.

We know little about file B from your diagram we can see it's size is much smaller then file A and from your description  it needs to be resized for file A size and there may be a horizontal row marker in some of the file b files  That should be align with row 1300 in file A else align something other perhaps the image bottom edge.

We do not know any real resize information sizes or aspect rartio.  We know that curren document B need to be resized but have no informataio of what that resize size should be that is required for file A size..

JJMack
Translate
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
New Here ,
Feb 28, 2018 Feb 28, 2018

Thank you very much to everyone who helped, particularly r_bin for providing the code that answered the question.  Invaluable.  Thank you all so much.

Translate
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