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

I want to save as jpg with the same name as the selected layer.

Community Beginner ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

Hi all,

 

I want to save as jpg with the same name as the selected layer.

The process is like this. I need to manually select a layer then run a script/action/whatever to save the image file with jpeg quality 12 in the same folder as the PSD file. The name of the file should be the same as the layer name I have manually selected.

 

Thanks in advance!

TOPICS
Actions and scripting , Windows

Views

185

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 2 Correct answers

Community Expert , Mar 28, 2024 Mar 28, 2024
quote

I need to turn on the visibility of that layer, save the file with the name of that selected layer.

Then turn manually some layers off and some other layers on. Then select again a layer to get the file name for the save and so on.


By @Dusan331314882hci

 

Try this script:

 

/*
Save JPEG Using Active Layer Name.jsx
v1.1, 29th March 2024, Stephen Marsh
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-jpg-and-combining-the-visual-layer-names-to-create-the-file-name/
...

Votes

Translate

Translate
Community Expert , Mar 28, 2024 Mar 28, 2024

I have updated the original code to a new 1.1 version.

 

As per your example, there is no space between the docName and layerName:

 

var jpgSave = new File(docPath + "/" + docName + "" + layerName + ".jpg");

 

I have left a placeholder there to add a space or another separator character if needed, in the example below an _ underscore character:

 

var jpgSave = new File(docPath + "/" + docName + "_" + layerName + ".jpg");

 

Votes

Translate

Translate
Adobe
Community Expert ,
Mar 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

@Dusan331314882hci 

 

I presume that you need to toggle off the visibility of all other layers, so that only the active layer content is saved as a JPEG? Then set the layer visibility back to how it was beforehand...

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

I need to turn on the visibility of that layer, save the file with the name of that selected layer.

Then turn manually some layers off and some other layers on. Then select again a layer to get the file name for the save and so on.

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

You can use Generate Assets perhaps? Although it doesn't save in the same folder, but in a sub-folder named assets-filename.

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

I do need to save all layers one by one. The images I am saving are a combination of multiple layers visible when saving, I am just using the SELECTED layer as the file name so I should not type it later on.

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

Hi!

If you use the Export>Layers to files feature under the File menu, you can do just that.

1. Name the layer whatever name you like.

2. Make sure the layer visibility is turned on.

3. Choose File>Export>Layers to files and in the dialog box choose where you want to save them images, choose your general file name and the quality of hte jpg.

4. Click Run. It will automatically save your file with the Layer name in addition to the general name you give it.

Let us know if that helps!

Michelle

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

Hi! I am sorry, maybe I was not clear enough. I am not exporting layers. I am saving the whole image that is made of a few dozen layers. This is a model that is wearing pants and I have 800 textures that I need to apply. The basic images is a model of a guy with several layers of shadows and some adjustment layers. These should always be present on the final image. The only thing that is changed is the visibility of the textures which are put in separate layers. And the pants are made of several different layers of the same texture. So I need to combine these textures (4 of them to be precise) but turning their visibility off and on and when I make the setup, I save the image using one of the layers as the name for the new file. The model with the shadows and adjustment layers are always turned on.

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

quote

I need to turn on the visibility of that layer, save the file with the name of that selected layer.

Then turn manually some layers off and some other layers on. Then select again a layer to get the file name for the save and so on.


By @Dusan331314882hci

 

Try this script:

 

/*
Save JPEG Using Active Layer Name.jsx
v1.1, 29th March 2024, Stephen Marsh
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/export-jpg-and-combining-the-visual-layer-names-to-create-the-file-name/td-p/13617072
*/

#target photoshop

(function () {
    // Set the doc and path variables
    var doc = app.activeDocument;
    var docName = doc.name.replace(/\.[^\.]+$/, '');
    try {
        var docPath = doc.path.fsName;
    } catch (e) {
        var docPath = Folder.selectDialog("Unsaved base file, select the output folder:");
    }

    // Clean the layer name, place characters to be retained inside the [] brackets...
    var layerName = doc.activeLayer.name.replace(/[^a-z0-9 -_]/gi, '').replace(/^ +| +$/g, '');
    var jpgSave = new File(docPath + "/" + docName + "" + layerName + ".jpg");

    // Check for existing file
    if (jpgSave.exists) {
        // true = 'No' as default active button
        if (!confirm("File exists, overwrite: Yes or No?", true))
            return;
    }

    // Setup the save options
    var jpgOptns = new JPEGSaveOptions();
    jpgOptns.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgOptns.embedColorProfile = true;
    jpgOptns.matte = MatteType.NONE;
    jpgOptns.quality = 12;
    doc.saveAs(jpgSave, jpgOptns, true, Extension.LOWERCASE);
}());

 

Note:

 

Layers can have special characters that are illegal when used as a filename.

 

In the code you will find the following section, simply add any special characters that you wish to retain inside the [ ] square brackets:

 

[^a-z0-9 -_]

 

The code currently retains alpha-numeric characters, digits, word spaces, hyphens and underscore characters.

 

If you wished to add a $ sign, then you would do so similar to this:

 

[^a-z0-9 -_$]

 

Keep in mind that Photoshop may still remove illegal characters anyway.

 

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

This is working like a charm Stephen! Thank you so much! Where could I add the name of the main file as a prefix? So if the main file with all the layers is called "MainPants.psd" and I run the script then I should get MainPants37.jpg (so without the extension PSD). Thanks again!

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

I have updated the original code to a new 1.1 version.

 

As per your example, there is no space between the docName and layerName:

 

var jpgSave = new File(docPath + "/" + docName + "" + layerName + ".jpg");

 

I have left a placeholder there to add a space or another separator character if needed, in the example below an _ underscore character:

 

var jpgSave = new File(docPath + "/" + docName + "_" + layerName + ".jpg");

 

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

This is working great, I just see it now! Great work, man, and thank you once again!

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 28, 2024 Mar 28, 2024

Copy link to clipboard

Copied

LATEST
quote

This is working great, I just see it now! Great work, man, and thank you once again!


By @Dusan331314882hci

 

You're welcome!

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