Batch export Photoshop PSD files to PNG the right way

I have seen many different ways to batch convert/export Photoshop PSD files to different formats, like creating actions, macros, custom scripts, or use any of many of the third party applications on the market.

Some different problems I have encountered during those different approaches are:

  • The output mismatches the input, some filters applied disappears. Layer groups and hidden layers may or may not get rendered (often applies to 3rd part applications).
  • Actions and macros in Photoshop does a good rendering job, but takes forever because it is semi automatic. It makes my workstation almost impossible to work with during the process and still need my input. I have to open up all my high-res images and then start the process. This makes it almost impossible for bigger batch work where hundreds of gigabytes of PSD files are about to get processed.
  • Memory consumption during the process described above in my usual scenario with single files up to 1 GB makes me process maximum of five files at a time without my workstation throwing in the towel.

Yesterday I received another of those gigabyte batches of files on my table and after some debate with the art director about the possibilities to get the files in the correct format I started writing an ExtendScript for Photoshop to do the job. I had done some similar scripting work a couple of years ago automating InDesign so it was quite straight forward.

This is the result:
#target "photoshop"

var outputWidth = 1024;
var inputFolder = Folder.selectDialog("Input folder");
var outputFolder = Folder.selectDialog("Output folder");

if (inputFolder != null && outputFolder != null) {
    var files = inputFolder.getFiles("*.psd");

    for (var i = 0; i < files.length; i++) {

        var file = files[i];
        var doc =;

        if (doc.width > outputWidth) {
            var height = (doc.height / doc.width) * outputWidth;
            doc.resizeImage(outputWidth + "px", height + "px");

        var options = new ExportOptionsSaveForWeb();
        options.format = SaveDocumentType.PNG;
        options.PNG8 = false;

        doc.exportDocument(outputFolder, ExportType.SAVEFORWEB, options);
        $.writeln('File ' + (i + 1) + ' of ' + files.length + ' processed');

Just save it to a file with jsx extension or download it here, execute the file and choose you input and output folder and then go for lunch. With the default settings it resizes the image to a width of 1024px. This can be easily changed by editing outputWidth to your desired width and the aspect is kept.

  • Chris Foster

    Good work..

    Image units may need converting pixels…“px”)


    • psd to png

      Good work the both of you.

      Chris could you explain what you menat for “Image units may need converting pixels…“px”)
      If you could re-write the part of the script where that goes!

  • rob hanson

    Well done! This saved me a lot of tedious clicking and the results are perfect.

  • J.T Dabbagian

    Thanks so much, you just saved me from extremely repetitive work!

  • PSD Files,Photoshop file,Download PSD File,Download,PSD,Free PSD,downloads

    I am fairly good with photoshop, but i dont know much about batch processing. For a class photo shoot I had to take 80 pictures of students in their halloween costumes and print them with a border. is there any way I can batch process these pictures so that the border can be placed over the image and exported as jpeg so I can send them electronically as well as print them all at once? I feel like there is some way to do it a lot faster than saving as for each photo. I am using cs5

  • Abhishek Kumar

    I selected an input folder with a PSD file in it and another output folder.

    I am getting error ” Couldn’t complete the Action, since the destination folder does not exist”.

    Can you help?

  • http://- hayit

    it dosent work with me and give the error “could not complete the Action, since the destination folderdoes not exist”…But i couse the folder… Help…Please

  • http://- MUSTAFA HAYIT

    that is perfect script but I tried it and it doesn’t work CS5 give the error “Could not complete the Action, since the destination folder does not exist. ” Please help.

  • Jon

    This script is working just how I need it to. However it is not changing the width. I need the file to 350 x 350. When I run the script, the image is created, the debugger gets stuck on the 350. The file dimensions are not changed. Any ideas?

    I only changed

    var outputWidth = 1024;


    var outputWidth = 350;

  • Mike James

    Hi Andreas,

    First of all, thanks for providing the script on this, it will help a ton.
    I just have a concern, when I run the script, the output files are png but they end up having a black background instead of a transparent background.

    How/what do I do to fix this? I guess it’s just a matter of adding a transparency option on the script?

    I really hope you can help.

    Thanks so much!


    Hi there just wanted to give you a quick heads up.
    The words in your article seem to be running off the screen in
    Internet explorer. I’m not sure if this is a format issue or something
    to do with web browser compatibility but I figured I’d post to let you know.
    The design and style look great though! Hope you get the issue
    fixed soon. Kudos

  • michaelminor

    Fantastic script. I however found it a bit limiting, so I merged it with another script I found on git.
    Enjoy 😀

  • NewYears1978

    Does this open the image and then save it just like an action would? If so it’s still slow (currently batching right now)… was hoping for a fast alternative but it seems there is no way to quickly batch PSD to PNG :

    If I could export data sets directly to PNG that would have solved my issue..but you can’t do that either :

    • brat007

      I dont understand : what do you mean “export data sets”? I write scripts for ps. I could help ($)