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

Saving multiple JPEG's without manually changing layers

Community Beginner ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

Hi, 

I've approached a little problem with saving hundreds or even thousands of pictures for a web shop. I have at least 20 to 25 variants of the same picture but I cannot move, hide or delete any other layer of group, just this one particular group. Is there any solution besides Layers to Files? 

 

Probably explained it very poorly so I've managed to pull up some examples in attachments 😕

 

I don't mind leaving unchanged names behind, I am just curious if it's possible to save some time with "Save As" option 🙂 

 

 

TOPICS
Windows

Views

782

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

Community Expert , Mar 20, 2023 Mar 20, 2023

Here is a custom script for the task:

 

/*
Save JPEG Files from Patterns Group.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/automate-an-export-with-some-visible-layers/m-p/13572441
Based on
https://community.adobe.com/t5/photoshop-ecosystem-discussions/way-to-turn-on-the-next-hidden-layer-to-automate-comps/td-p/13450230
v1.0 21st March 2022, Stephen Marsh

Info: Saves all visible layers with only one layer visible from the 'patterns' group as a JPEG file. The file will be n
...

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

Hi @tr0j4n if your layer names are consistent, you could have an action or script turn layer visibility on and off and save, but you'd run into the issue of file naming. I'm sure somone here may have a scripted solution they can offer.

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 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

It sounds like you wish to save all visible layers with only a single layer active/visible from the "patterns" group for each save... If so, start with this script (it saves PNG and PSD, but that can be changed):

 

https://github.com/mechanicious/photoshopCompositionComposer

 

Info on saving/downloading/installing scripts here:

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

EDIT: This version saves JPEG rather than PNG:

 

// https://github.com/mechanicious/photoshopCompositionComposer
// Modified to save JPEG rather than PNG

var userDisplayDialogsPref = app.displayDialogs;

app.displayDialogs = DialogModes.ALL;

var savePath;

app.displayDialogs = DialogModes.NO;

function getType(thing) {
  if (thing === null) return "[object Null]"; // special case
  return Object.prototype.toString.call(thing);
}

function getCombinations(arr, n) {
  if (n == 1) {
    var ret = [];
    for (var i = 0; i < arr.length; i++) {
      for (var j = 0; j < arr[i].length; j++) {
        ret.push([arr[i][j]]);
      }
    }
    return ret;
  } else {
    var ret = [];
    for (var i = 0; i < arr.length; i++) {
      var elem = arr.shift();
      for (var j = 0; j < elem.length; j++) {
        var childperm = getCombinations(arr.slice(), n - 1);
        for (var k = 0; k < childperm.length; k++) {
          ret.push([elem[j]].concat(childperm[k]));
        }
      }
    }
    return ret;
  }
}

function showAllArtLayers() {
  for (var i = 0; i < layerSets.length; i++) {
    for (var z = 0; z < layerSets[i].artLayers.length; z++) {
      layerSets[i].artLayers[z].visible = true;
    }
  }
}

function hideAllArtLayers() {
  var layerSets = app.activeDocument.layerSets;

  for (var i = 0; i < layerSets.length; i++) {
    if (layerSets[i].artLayers.length) {
      for (var z = 0; z < layerSets[i].artLayers.length; z++) {
        layerSets[i].artLayers[z].visible = false;
      }
    } else {
      for (var z = 0; z < layerSets[i].layerSets.length; z++) {
        layerSets[i].layerSets[z].visible = false;
      }
    }
  }
}

function getArtLayerCollectionCollection() {
  var layerSets = app.activeDocument.layerSets,
    artLayerCollectionCollection = [];

  for (var i = 0; i < layerSets.length; i++) {
    var artlayerCollection = [];
    if (layerSets[i].artLayers.length) {
      for (var z = 0; z < layerSets[i].artLayers.length; z++) {
        if (layerSets[i].name.indexOf('__') !== 0)
          artlayerCollection.push(layerSets[i].artLayers[z]);
      }
    } else {
      for (var z = 0; z < layerSets[i].layerSets.length; z++) {
        if (layerSets[i].name.indexOf('__') !== 0)
          artlayerCollection.push(layerSets[i].layerSets[z]);
      }
    }
    artLayerCollectionCollection.push(artlayerCollection);
  }

  return artLayerCollectionCollection;
}

function combine() {
  var artLayerCollectionCollection = getArtLayerCollectionCollection(),
    artLayerCollectionCollectionCombinations = getCombinations(artLayerCollectionCollection, getLayerSetsCount()),
    continueConfirmation;

  if (!artLayerCollectionCollectionCombinations.length) return alert('Script has aborted. No combinations found. Please make sure no empty groups are present.');

  continueConfirmation = confirm(artLayerCollectionCollectionCombinations.length + " combinations found. Would you like to continue?");

  if (!continueConfirmation) return alert('Script has been aborted.');

  savePath = Folder.selectDialog("Select an output folder");

  var includePSDFiles = confirm('Would you like to include corresponding PSD documents?')

  for (var i = 0; i < artLayerCollectionCollectionCombinations.length; i++) {
    hideAllArtLayers();
    var artLayerNames = [];
    for (var z = 0; z < artLayerCollectionCollectionCombinations[i].length; z++) {
      var artLayer = artLayerCollectionCollectionCombinations[i][z];
      artLayer.visible = true;
      artLayerNames.push(artLayer.parent.name + " "); // Add a space after the parent group name
      artLayerNames.push(artLayer.name);
    }
    saveDocumentAsJPEG(savePath + '/' + normalizeSaveFileName(artLayerNames.join('')).substr(0, 254));
    if (includePSDFiles) saveDocumentAsPSD(savePath + '/' + normalizeSaveFileName(artLayer.parent.name + artLayerNames.join('')).substr(0, 254));
  }
}

function getSmallestLayerSetCount() {
  var count = null,
    layerSets = app.activeDocument.layerSets;

  for (var i = 0; i < layerSets.length; i++) {
    var artLayers = layerSets[i].artLayers;

    if (count === null) count = artLayers.length;

    if (artLayers.length < count) count = artLayers.length;
  }

  return 1;
}

function getLayerSetsCount() {
  var layerSets = app.activeDocument.layerSets,
    count = 0;

  for (var i = 0; i < layerSets.length; i++) {
    if (layerSets[i].name.indexOf('__') !== 0) count++;
  }

  return count;
}

function normalizeSaveFileName(name) {
  return name;
}

function saveDocumentAsJPEG(path) {
  jpgSaveOptions = new JPEGSaveOptions();
  jpgSaveOptions.matte = MatteType.NONE;
  jpgSaveOptions.embedColorProfile = true;
  // STANDARDBASELINE | OPTIMIZEDBASELINE | PROGRESSIVE
  jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
  // Quality  0 low quality - 12 high quality
  jpgSaveOptions.quality = 10;
  if (jpgSaveOptions.formatOptions == FormatOptions.PROGRESSIVE) {
    // Only valid for Progressive: 3 - 5
    jpgSaveOptions.scans = 3;
  }

  app.activeDocument.saveAs(new File(path), jpgSaveOptions);
}

function saveDocumentAsPSD(path) {
  app.activeDocument.saveAs(new File(path), new PhotoshopSaveOptions());
}

combine();

app.displayDialogs = userDisplayDialogsPref;

 

A custom solution would likely require a better explanation, sample file, before/after examples etc.

 

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 20, 2023 Mar 20, 2023

Copy link to clipboard

Copied

Here is a custom script for the task:

 

/*
Save JPEG Files from Patterns Group.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/automate-an-export-with-some-visible-layers/m-p/13572441
Based on
https://community.adobe.com/t5/photoshop-ecosystem-discussions/way-to-turn-on-the-next-hidden-layer-to-automate-comps/td-p/13450230
v1.0 21st March 2022, Stephen Marsh

Info: Saves all visible layers with only one layer visible from the 'patterns' group as a JPEG file. The file will be named after the 'patterns' layer name, duplicate layers will have a unique layer name to avoid overwriting existing files.
*/

#target photoshop

if (documents.length) {

    function main() {

        // Select the "patterns" group
        activeDocument.activeLayer = activeDocument.layerSets["patterns"];

        // Check for active layer group and case sensitive name of "patterns"
        if (activeDocument.activeLayer.typename === "LayerSet" && activeDocument.activeLayer.name === "patterns") {

            // Set the output folder
            var docSavePath = Folder.selectDialog("Select the JPEG save folder:");

            // Setup the script timer
            var timeDiff = {
                setStartTime: function () {
                    d = new Date();
                    time = d.getTime();
                },
                getDiff: function () {
                    d = new Date();
                    t = d.getTime() - time;
                    time = d.getTime();
                    return t;
                }
            };
            timeDiff.setStartTime();

            // All child layers in the parent group should be hidden at the start of the script
            for (var i = 0; i < activeDocument.activeLayer.layers.length; i++) {
                activeDocument.activeLayer.layers[i].visible = false;
            }

            // Set the doc variable
            var doc = app.activeDocument;
            

            // Set the file processing counter at zero
            var counter = 0;

            // Loop over the contents of the selected layer group and save JPEGs
            for (var i = 0; i < activeDocument.activeLayer.layers.length; i++) {
                var layerName = activeDocument.activeLayer.layers[i].name;
                activeDocument.activeLayer.layers[i].visible = true;
                var jpgSave = new File(docSavePath + "/" + layerName + ".jpg");

                // Check for existing file and make the filename unique
                if (jpgSave.exists) {
                    jpgSave = new File(docSavePath + "/" + layerName + " - Duplicate " + counter + ".jpg");
                }

                // Setup the save options
                var jpgOptns = new JPEGSaveOptions();
                jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
                jpgOptns.embedColorProfile = true;
                jpgOptns.matte = MatteType.NONE;
                jpgOptns.quality = 10;

                // Save the JPEG
                doc.saveAs(jpgSave, jpgOptns, true, Extension.LOWERCASE);

                // Reset the layer visibility
                activeDocument.activeLayer.layers[i].visible = false;

                // Increment the file processing counter
                counter++;
            }

            // Select the top layer in the 'patterns' group
            activeDocument.activeLayer = app.activeDocument.layerSets["patterns"].layers[0];

            // End of script notification
            alert(counter + " JPEG files created!" + "\n" + "(" + timeDiff.getDiff() / 1000 + " seconds)");

        } else {
            alert("The selected layer isn't a layer group or isn't named 'patterns'!");
        }

    }
    activeDocument.suspendHistory("Save JPEG Files from Patterns Group...", "main()");

} else {
    alert("A document must be open to run this script!");
}

 

 

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 Beginner ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Thank you for this, it would be my first time using this kind of complicated script but I don't know where to start 😄 Do I save this custom script as .jsx file and before running it in Scripts, should I take care of naming layers and groups? I will be filled with tears of joy if it's that easy!

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 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

@tr0j4n 

 

The first script is generic, follow the instructions for use at the original link.

 

The second custom script requires the layer group to be named 'pattern' as per your screenshot.

 

In both cases, the full instructions for saving and running scripts are here:

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

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 Beginner ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Missed a message with a tutorial before this.. I'll try my best and I will come back with the results!

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 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

If you do please provide a better description of the intended process and a sample layered iamge and the intended results (or at least screenshots that illustrate the Layer structure and the intended resulting files). 

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 Beginner ,
Mar 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

Job done, thank you so much! It saved me from clicking "Save as.." hundreds of times. Now onto the names 🙂

 

Dropped some attachments to confirm the process!

 

Thank you 🙂

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 21, 2023 Mar 21, 2023

Copy link to clipboard

Copied

LATEST

You're welcome, my script doesn't use the '__ignore this group' feature, but it sounds like you got a result!

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