Skip to main content
Participating Frequently
January 23, 2018
Answered

Combining 2 JPG files into layers from multiple folders

  • January 23, 2018
  • 3 replies
  • 1415 views

I have 2000+ jpg's that are in approximately 1000 folders—each folder contains 2 jpg files. I would like know if there is a script that creates a psd file with a specified canvas size, a white background layer, and each jpg file into a layer. Is this possible? If so any help would be appreciated, thanks. I'm using Photoshop CS6.

This topic has been closed for replies.
Correct answer Kukurykus

After user ran script and chose folder to be processed:

  • it browses all contained folders (also the most deepest ones of them)
  • if in any found folder there is less / more than two .jpg files it ignores all
  • if there are also other subfolder(s) / file(s) of other type it ignores them too
  • when there are exactly 2 jpg's only, or between other files / folders it opens them
  • two files are compared for resolution and that with less is pasted to jpg with higher
  • if a width / height of one file is bigger than other then document canvas are resized
  • background is created while two jpg layers get their file names without extension
  • .psd is saved in the folder where 2 jpg files are stored with a name of that folder

function FSf(sF, i) {

     sF = Folder(sF).getFiles()

     for(re = /\.jpe?g$/i; i < sF.length; i++) {

          if (sF instanceof Folder) FSf(sF, 0)

          else if((sF.parent.getFiles(re).length == 2)) {

               if ((dl = (d = documents).length) < 2

               && (re).test(String(sF))) {

                    open(sF); function sel() {

                         (sel = d[dl].selection)

                         .selectAll(), sel.copy()

                    }

                    if (dl + 1 < 2) sel(), r = d[dl].resolution

                    else {

                         if (b = d[dl].resolution <= r) sel()

                         nme = d[+b].name, d[+b].close();

                         function splt(v) {return v.split(re)[0]}

                         function iBL(v1, v2) {

                              return v1.isBackgroundLayer = v2

                         }

                         with(d[0]) {

                              iBL((lyr = layers)[0], false)

                              lyr[0].name = splt(name), paste(),

                              lyr[0].name = splt(nme), revealAll()

                              artLayers.add(), iBL(lyr[0], true)

                              saveAs(File((nme = sF.path) + '/'

                              + File(nme).name + '.psd')), close()

                         }

                    }

               }

          }

     }

}

FSf(Folder.selectDialog('Please select top level folder'), 0)

3 replies

JJMack
Community Expert
Community Expert
January 24, 2018

Did you search the forum? There have been threads on this subject before and some scripts posted.

https://forums.adobe.com/search.jspa?place=%2Fplaces%2F1383833&q=pairs

JJMack
Participating Frequently
January 30, 2018

Yes, I found the one created 3 years ago and was about to modify my file structure to match the script. But I just received a new script that takes my file structure into account. I'm going to give this a try. Thanks for your response.

Kukurykus
KukurykusCorrect answer
Legend
January 24, 2018

After user ran script and chose folder to be processed:

  • it browses all contained folders (also the most deepest ones of them)
  • if in any found folder there is less / more than two .jpg files it ignores all
  • if there are also other subfolder(s) / file(s) of other type it ignores them too
  • when there are exactly 2 jpg's only, or between other files / folders it opens them
  • two files are compared for resolution and that with less is pasted to jpg with higher
  • if a width / height of one file is bigger than other then document canvas are resized
  • background is created while two jpg layers get their file names without extension
  • .psd is saved in the folder where 2 jpg files are stored with a name of that folder

function FSf(sF, i) {

     sF = Folder(sF).getFiles()

     for(re = /\.jpe?g$/i; i < sF.length; i++) {

          if (sF instanceof Folder) FSf(sF, 0)

          else if((sF.parent.getFiles(re).length == 2)) {

               if ((dl = (d = documents).length) < 2

               && (re).test(String(sF))) {

                    open(sF); function sel() {

                         (sel = d[dl].selection)

                         .selectAll(), sel.copy()

                    }

                    if (dl + 1 < 2) sel(), r = d[dl].resolution

                    else {

                         if (b = d[dl].resolution <= r) sel()

                         nme = d[+b].name, d[+b].close();

                         function splt(v) {return v.split(re)[0]}

                         function iBL(v1, v2) {

                              return v1.isBackgroundLayer = v2

                         }

                         with(d[0]) {

                              iBL((lyr = layers)[0], false)

                              lyr[0].name = splt(name), paste(),

                              lyr[0].name = splt(nme), revealAll()

                              artLayers.add(), iBL(lyr[0], true)

                              saveAs(File((nme = sF.path) + '/'

                              + File(nme).name + '.psd')), close()

                         }

                    }

               }

          }

     }

}

FSf(Folder.selectDialog('Please select top level folder'), 0)

Participating Frequently
January 30, 2018

Thanks, I'll give this a try!

Kukurykus
Legend
January 30, 2018

I wrote you script that does that you want. At least it seems so from that you're saying. Did you give it a try? @Jarda Bereza answer solves your problem that you mark his question as correct solution, does it work better for you than script I wrote?

Jarda Bereza
Inspiring
January 23, 2018

Do you want 1000 PSD files with 2 layers or 1 PSD file with 2000 layers?

Participating Frequently
January 30, 2018

Correct 2 jpg files into 1 psd file.