How to export multiple layers to a png file from photoshop automatically

Thomas Zucker-Scharff
Thomas Zucker-Scharff used Ask the Experts™
on
I had this question after viewing Photoshop CS6 Export Multiple Layers with Fixed Top Layer Effect on All.  I have an extremely large (383mb) psd file with over 200 layers.  I created the file using photoshop CC (current verison is 2019).  In it I have several base layers that I use for the background for the other layers.  So if I export the layers as a png file I might select layer 6 (which has several styles applied to it) and layer 10 as one image, then layer6 and layer 11, then layer 6 and layer 12, etc.  Sometimes I select the base layer (layer 6) and 2 to 3 other layers in combination.  I want to be able to automate this as much as possible.  I could save a copy of the psd and then flatten each layer so there would never be more than 2 layers selected (the base and the one I am selecting).  There must be some way to do this within photoshop!  Any ideas would be appreciated (I also wouldn't mind getting this large file downsized a little - over 380mb is far too large).
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
David FavorFractional CTO
Distinguished Expert 2018

Commented:
What your describing is a Photoshop API, where you can call some API service to do something like export certain layers as a .png image.

The search - https://github.com photoshop api - turns up what a appears to be the Adobe API project.

I don't see any calls for exporting one or more layers to an image file.

Likely best if you open an issue ticket with the doc project + ask for the doc URL describing your exact requirement.

https://github.com/AdobeDocs/photoshop-api-docs looks to be the related documentation project.
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
I can't imagine dealing with 200 layers, but I can imagine how that can build up too!

I think what you want to do is use linked files http://blogs.adobe.com/richardcurtis/2015/11/20/creativefriday-photoshop-place-linked-vs-place-embed/

Then you can link things like backgrounds.  Lets say you have folder for your project.  And in that project folder you have your psd files. image_1.psd, image_2.psd and image_3.psd  Also in that project folder you have a sub folder for background images where you have 50 different backgrounds.  You can place-link any of the background images to your psd files.  For image_1.psd file you may place-link background-A which is blue.  In the future, you may switch background-A to Red and that would update those linked files. More than likely you would want to just remove the current backgound and choose another.    

At least this will allow you to use images outside of your psd file and prevent it from getting very large.

As far as automation goes, what do you want to automate?  Look to see if built in automation such as using data driven layers can assist https://helpx.adobe.com/photoshop/using/creating-data-driven-graphics.html#creating_data_sets_in_external_files

If you do need to do something that is more automation heavy where any very advanced transformations are already done, you may want to look at imagemagick or http://www.graphicsmagick.org.  I use this myself as well as photoshop. When I need to pull things together from a database, I use this along with basic transformations such as colorization, transparency, convert etc.  It works at the command line so you can use just about any language.

Author

Commented:
I am not, as you might have guessed, a graphics designer.  I am using Photoshop because of its layer functionality, and our institution has a license to Adobe Creative Cloud.  I will look into your suggestions, the API project does not look very far along (besides I am not very good with APIs) and although Scott's ideas are more to the point the links seem to address outputting the files as PSD's, not PNG's.  Linking would certainly help with the file size, I may try it, but it also looks, at least on the surface, like one would lose a lot of control over the editing procedure.  

Since I wrote this question the PSD has grown from over 200 layers to nearly 250 layers and the file size, even after using several ways to reduce it, has grown as well.  Since I only have 6 backgrounds currently, I may try the linking idea.

I will get back to this question after I have tried several more things out.  Thanks.
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
cott's ideas are more to the point the links seem to address outputting the files as PSD's

The PSD's are used to output PNG's.  I do not believe you can use photoshop layers with a  PNG.  The idea of linking external files instead of embedding them will cut down the size of the PSD.  What I am suggesting is using a template.  Without knowing what you are actually doing, it is hard to give a more detailed idea.  I find when things start getting overly complex, it is time to break things down to smaller chunks. That could be the issue here.

Are you keeping the 250 layers just to keep everything in one place?
UX/UI Designer
Commented:
Hi Thomas! As you are still working on this file, I do have some suggestions for achieving the desired results going forward (and backward, time willing).

Layer Comps
I don't believe this functionality is shown by default, but you can enable it by selecting Layer Comps under Window. The icon should appear on the right (assuming default workspace) and looks like a small magazine page.

  1. Make visible the layers you wish to export (like layers 6 and 11), and click the icon left of the trash can to Create New Layer Comp. Name the layer comp as you wish with Apply to Layers: Visibility select. You would do this for every comp you plan to export.
  2. Once you have all of your comps set, you can then use File > Export > Layer Comps to Files. Here you can select PNG (or others) and whether you wish to export all comps or just the comps you had selected in the Layer Comp window before selecting Export. Click Run and lean back. :)

Smart Objects
If you are worried about having a cluster of layers, I highly recommend using Smart Objects. So for example, let's say you need a background with 15 layers. Create your layers, select them, then right-click and select Convert to Smart Object. Those 15 layers will be replaced with one. If you need to edit, you can double-click that layer and it will open a new Photoshop tab, which you then edit, ctrl + S, and close the tab. When you return to your primary document, the Smart Object (and any copies of it) will be updated.

File Size
Large PSDs are a result of numerous factors including Smart Objects, layer styles, layer count, masks, artboards, etc. The key I've found is reducing unnecessary layer styles. Maybe you changed your mind and want a background to be blue instead of grey, but you applied a layer style. Right-click and Rasterize Layer Style. Maybe you don't need a mask anymore? Right-click and Apply Layer Mask. Merging layers, rasterizing styles, and keeping Smart Objects to a minimum can help keep your PSD size at bay.
LayerComps.jpg

Author

Commented:
Scott,

I have combined 3 different projects in one file, my initial reasoning is that I am using the same bases for the different projects (a base background button with styles).  About 20-50 layers comprise one of the projects and about 75-100 layers comprise another project.  The third project is what is left (now nearly 250 layers in all - 6 of them are different background layers).  So breaking them up is certainly an option.

Emily,

I like a lot of your ideas.  I am currently trying out the layer comps.  Although this initially looks like a lot of work, it may be worth it (I hope).  

I googled how to reduce the file size without losing any editing ability and tried several ideas on a copy of the file.  Just putting in a solid white layer on top of everything else reduced the size by 1mb (not a lot, but something).

Author

Commented:
Thanks to everyone.  I will be splitting the file up into the separate projects and using layer comps - these are great.  The only downside I see is that one would need to create new layer comps if I change the background image.
Emily PhelanUX/UI Designer

Commented:
Awesome! Happy to help. :)

The only downside I see is that one would need to create new layer comps if I change the background image.

Unless the background is a Smart Object!  If you mean to create a different background for different items, then sadly yes.

Author

Commented:
Unless the background is a Smart Object!
 What do you mean.  I am a photoshop newbie.  I have 5 basic backgrounds for my button.  can I make them into smart objects if they aren't?  How would this help (I noticed the refresh in the layer comps tab - maybe that?)?

BTW I made all the layer comps and it works like a charm!!!!
Emily PhelanUX/UI Designer

Commented:
Apologies! Yes, you can make Smart Objects even if they are not by right-clicking the background layer in the Layers panel and selecting "Convert to Smart Object." You can then double-click that layer and it will open a new Photoshop tab. Make whatever edits you need to your background, save, then return to your main document and the smart object will have updated.

Now, if you repeat that layer (ctrl +j or cmd +j), any changes you make will change will change every duplicate of this layer, so if you need a secondary background for other comps, you will need to make a new Smart Object with the steps from above.

If you already have a different PSD you want to use for the background, you can drag it into the main PSD and it will create a Smart Object layer for you as well. This is also possible with other file types that you want to maintain editing capabilities on, but I wouldn't do this with flat files as it will unnecessarily bloat your PSD size.

Author

Commented:
I'll have to try that with the background images I have - thanks again.  It is currently generating the png files from the layer comps, up to 120 out of 225.  I was happily surprised that creating the layer comps did not increase the PSD size.  I can't be exact since while creating the layer comps I also deleted some extraneous layers - ones created before I discovered I could resize a single layer within the PSD file by using ctrl-T.  I had some layers that were the same image but different sizes.
Emily PhelanUX/UI Designer

Commented:
Off topic sort of... but do you need the transparency from png? Jpeg files are usually smaller exports. Most people can't tell the difference between a High-Quality (80) jpeg versus a Max Quality (100). For example, an image I have open right now is 1mb as a High-Quality jpeg, but 5mb as a png.

Another thing, if you have a large image (bigger than your artboard), those unseen pixels are still costing you on file size. If you ever need to crop and you're not worried about changing your mind later, you'll want to check the box "Delete Cropped Pixels" in the top toolbar before you hit enter on that crop!

Author

Commented:
I do need the transparency.  But what is the difference, realistically, between png-8 and png-24?  Still working on getting the project down to size by splitting up the layers into their respective subprojects, each with all 6 of the backgrounds (which I might end up using linked files for anyway).
Emily PhelanUX/UI Designer

Commented:
A png-8 will be a smaller file size, but lacking in quality because it is processing less color. Depending on how much detail your require, there may not be a noticeable difference. If you have thin lines and/or glows or shadows, you may want to stick with png-24 though.

An option to preview before you export all of your comps is to File > Export > Save for Web. In the pop-up, select the "2-up" tab. Select one image and then choose png-8 from the dropdown on the right, then select the other image and choose png-24. You will be able to compare quality, file size, and download time.

Author

Commented:
Handy to know - Thanks (again)!  I hate to impose, but I have another question, that I have yet been unable to solve.  I am trying to move layers between files, so that the resulting file with it's layers will be exactly the same as the current one.  I have run into several problems.  When I use the 4 arrowed move tool to move the layers to the other file after selecting multiple layers, it works if I let go of the cursor while I am on the workspace of the new file, but it places the layers exactly where I dropped them instead of in the center.  I also seem to have layers that are larger than than the size of the workspace of either file!  I know I resized a bunch of layers after pressing CTRL-T while on the layer - would this do it?  

The result I want is to copy my base layers to each of 4 files, copy the appropriate layers to each of the files and save each separately.  The problem is the spacing and sizing that happens and the layers are all named layer1, layer2, layer3, etc. (instead of the layer names I gave them in the original file)  Is what I want possible?
Emily PhelanUX/UI Designer

Commented:
All of these problems are being caused by dragging items as opposed to cutting and pasting them.

To paste in the same location you will need to ctrl + shift + P or go to Edit > Paste > Paste Special > Paste into Place. I just tested this on my end and everything landed in place, with the same name, regardless of being larger than artboard. You'll also want to ensure the artboard you're pasting into is the same size and resolution or you will still have size issues.

Author

Commented:
Thanks I'll try that.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial