# Export photoshop layers programatically to individual pngs of different sizes

Hi there I'm trying to export all of the layers in my .psd to .pngs/.jpegs and I am having trouble exporting them so that the sizes of the individual .pngs are the size of the image they contain.

I have seen this thread which has a script that almost does this but since I'm a new user here I can't comment on it...if the creator of that script (Johannes) could respond i would be very grateful.

Have you heard of http://macrabbit.com/slicy/? I started using this and it makes it extremely easy to export all layers as .png or .jpg. with one click. From what I remember it makes the .png the same size as the image it contains. Might be worth looking into. It's made life easier for me.

You can create an Action to do this if you have a lot of layers to save. Regardless, here's what you do:

• Click on the layer in the layers palette and go under Layer > Duplicate Layer (you can also right click for this).
• In the dialog box that pops up, look at the bottom where it says Destination and select "New" from the drop down menu. This duplicates the layer in a new document.
• If the background of the new document is transparent, go to Image > Trim. Select transparent pixels and trim away top, bottom, left, right.

If the image had a background color, hide or delete that layer, then follow the step above. Then save the new document and then save for web.

• Right now I have a script which does this but it's highly inefficient to create and close hundreds of new documents so I'm trying to find a more efficient way to do the same thing. Also I want to do this programatically not by hand – daveroz Aug 13 '13 at 18:17

I ended up using slicy. it works very well: just had to write a script to create the folders so that slicy can read the psd correctly

Use this script below to save each layer into files. When you save them in seperate files you can create an action which makes the Image -> Trim move to cut the layers transparent pixels which you don't need for every file.