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

How to automatically add two images into layer in a single PSD or TIFF then save?

Explorer ,
Jun 26, 2023 Jun 26, 2023

Can someone help me how to perform this process?

Automatically combine two images into one layered PSD or TIFF image, then save.
Let's say I have a bunch of original images and retouched images in a folder.
Like this,

image_01.tiff

image_01_retouched.tiff

image_02.tiff

image_02_retouched.tiff
I would like some kind of script to automatically add retouched image into the second layer in the original image and then save the file. (It would be amazing if it could also change the file names as well)
Is this possible?

I'm doing this manually, and as you can guess, it's painful.
By opening both images and dragging the retouched image into the original image. Then save the file.

 

TOPICS
Actions and scripting , macOS
4.3K
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 3 Correct answers

Community Expert , Jun 27, 2023 Jun 27, 2023

@hosongn52153496 

 

I have cleaned up the code a little bit from the generic script previously posted and changed over to layered TIFF output:

 

/* 

Stack x2 Image Sets to Layered TIFF.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-automatically-add-two-images-into-layer-in-a-single-psd-or-tiff-then-save/m-p/13897545
v1.0 - 28th June 2023, Stephen Marsh

* This script requires input files from a single folder to be alpha/numeric sorting in order to stack in the correc
...
Translate
Community Expert , Jan 22, 2025 Jan 22, 2025

@hosongn52153496 

 

Let's make a minor change to the previous code to retain the Background layer, as that may be the only thing you need!

 

Find the following chunk of code:

 

// Set the base doc layer name
app.activeDocument = documents[0];
docNameToLayerName();

 

Delete or comment out // the 3rd line #78 for docNameToLayerName();

 

// Set the base doc layer name
app.activeDocument = documents[0];
//docNameToLayerName();

 

If required, further refinements can be made as previously discussed, a

...
Translate
Community Expert , Jan 22, 2025 Jan 22, 2025
quote

Hi @Stephen Marsh 

If I run the script as they are, the layer order will flip in the stacked file.


By @hosongn52153496

 

Find the following section in the code:

 

// Force alpha-numeric list sort
// Use .reverse() for the first filename in the merged file
// Remove .reverse() for the last filename in the merged file
fileList.sort().reverse();

 

Then change the last line #36 to:

 

// Force alpha-numeric list sort
// Use .reverse() for the first filename in the merged file
// Remove .reverse() fo
...
Translate
Adobe
Community Expert ,
Jan 22, 2025 Jan 22, 2025

@hosongn52153496 

 

Let's make a minor change to the previous code to retain the Background layer, as that may be the only thing you need!

 

Find the following chunk of code:

 

// Set the base doc layer name
app.activeDocument = documents[0];
docNameToLayerName();

 

Delete or comment out // the 3rd line #78 for docNameToLayerName();

 

// Set the base doc layer name
app.activeDocument = documents[0];
//docNameToLayerName();

 

If required, further refinements can be made as previously discussed, automatically saving the layered TIFF files into a subfolder without the prompt for you to select a folder.

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
Explorer ,
Jan 22, 2025 Jan 22, 2025

Hi @Stephen Marsh !
It works wonderfully! However, in my testing, the script won't work if the new file with the suffix is followed by '-' (dash)but works with '_' (underscore)
Is there a way to make the script work with dash as well or dash only? For example, 
Filename-top.tif



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 ,
Jan 22, 2025 Jan 22, 2025

Ah, I'll need to look into that, you didn't previously mention the filename formatting and there's nothing explicitly in there that I recall that would treat hyphens and underscores differently. Are you on Windows or Mac?

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
Explorer ,
Jan 22, 2025 Jan 22, 2025

Sorry about not mentioning it.
I'm on Mac.

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 ,
Jan 22, 2025 Jan 22, 2025

So pairs of files, such as:

 

Filename001.tif

Filename001-top.tif

 

Filename002.tif

Filename002-top.tif

 

etc.?

 

The script simply uses natural alpha-numeric sorting, it's not explicitly trying to find patterns.

 

It might be better if you provided real filename examples for testing.

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
Explorer ,
Jan 22, 2025 Jan 22, 2025

Hi @Stephen Marsh 

Your example is correct, but here are a few real file names.
526842A-Black_MC_068-top.tif
526842A-Black_MC_068.tif
8542156C-Red_MC_022-top.tif
8542156C-Red_MC_022.tif

If I run the script as they are, the layer order will flip in the stacked file.
If I change the hyphen to underscore, everything works perfectly. 
The top layer file is automatically generated; I can't change it to underscore when generated.
I can only rename them afterward, but I want to see if I can skip that step if possible.


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 ,
Jan 22, 2025 Jan 22, 2025
quote

Hi @Stephen Marsh 

If I run the script as they are, the layer order will flip in the stacked file.


By @hosongn52153496

 

Find the following section in the code:

 

// Force alpha-numeric list sort
// Use .reverse() for the first filename in the merged file
// Remove .reverse() for the last filename in the merged file
fileList.sort().reverse();

 

Then change the last line #36 to:

 

// Force alpha-numeric list sort
// Use .reverse() for the first filename in the merged file
// Remove .reverse() for the last filename in the merged file
fileList.sort();

 

Does that fix the layer order issue?

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
Explorer ,
Jan 22, 2025 Jan 22, 2025

I just tested this, and it works perfectly!
You are a genius!
Thank you, thank you, thank you!!!

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 ,
Jan 24, 2025 Jan 24, 2025
LATEST

@hosongn52153496 

 

That’s great, I didn’t expect the file sort order to be different between a hyphen and an underscore suffix separator!

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 ,
Jan 22, 2025 Jan 22, 2025

On a related note, I built a generic script with a GUI – "Stack Documents to Sets of N Layers" (this script doesn't retain the Background layer of the first doc, the expectation is that files are flattened or have single layers):

 

Stack_Documents_to_Sets_of_N_Layers_scriptUI_GUI_v1-1.png

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-automate-load-files-into-st...

 

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