Skip to main content
Marinapomorac
Inspiring
June 19, 2021
Question

Import multiple PNG and JPG files as individual Artboards

  • June 19, 2021
  • 4 replies
  • 7027 views

Hello.

 

The script available here doesn't work. https://community.adobe.com/t5/photoshop/import-images-to-artboards/m-p/8430829

 

Does anyone have a working solution?

 

I have 60 images in one folder and I need each to be Artboard, not layer. 

 

And also there is no way to convert all jpg files in one folder to png with photoshop? I tried action but it just gives me psb or jpg again. 

 

4 replies

Stephen Marsh
Community Expert
Community Expert
June 20, 2021

This script will require line 15 to be changed to include other formats, as it only opens PSD files... 

 

i.e., from:

(psd)

to:

(jpg|tif|psd|psb|tga|png)

 

#target photoshop

// Batch Save As sRGB PNG.jsx

displayDialogs = DialogModes.NO

// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx

if (BridgeTalk.appName == "photoshop") {
    app.bringToFront;

    var inputFolder = Folder.selectDialog("Select the source folder that contains the PSD files for save as PNG:");

    if (inputFolder != null) {
        var fileList = inputFolder.getFiles(/\.(psd)$/i);
        var outputFolder = inputFolder;

        for (var i = 0; i < fileList.length; i++) {
            if (fileList[i] instanceof File) {
                var document = open(fileList[i]);
                var documentName = fileList[i].name.replace(/\.[^\.]+$/, ''); // Regex remove filename extension

                while (app.documents.length) {
                    var newFile = new File(decodeURI(outputFolder) + "/" + documentName + ".png");

                    // document.flatten (); // Disable flatten image step

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    function ConvertTosRGBProfile() {
                        app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
                    }
                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    var pngOptions = new PNGSaveOptions();
                    pngOptions.compression = 0
                    pngOptions.interlaced = false;
                    app.activeDocument.saveAs(newFile, pngOptions, true, Extension.LOWERCASE);
                    app.activeDocument.close();

                }
            }
            if (i == fileList.length - 1) {
                alert("All PSD files have been saved as PNG files!");
            }
        }
    }
}

 

Here is an Export/Save for Web version:

 

#target photoshop

// Batch Export SfW sRGB PNG.jsx

displayDialogs = DialogModes.NO

// raw.githubusercontent.com/jonahvsweb/Photoshop-Automated-Resize-to-Web.jsx/master/Automated%20Resize%20To%20Web.jsx

if (BridgeTalk.appName == "photoshop") {
    app.bringToFront;

    var inputFolder = Folder.selectDialog("Select the source folder that contains the PSD files for PNG export:");

    if (inputFolder != null) {
        var fileList = inputFolder.getFiles(/\.(psd)$/i);
        var outputFolder = inputFolder ;

        for (var i = 0; i < fileList.length; i++) {
            if (fileList[i] instanceof File) {
                var document = open (fileList [i]);
                var documentName = fileList [i].name.replace(/\.[^\.]+$/, ''); // Regex remove filename extension

                while (app.documents.length) {
                    var newFile = new File(decodeURI(outputFolder) + "/" + documentName + ".png");

                    // document.flatten (); // Disable flatten image step

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    function ConvertTosRGBProfile() {
                            app.activeDocument.convertProfile("sRGB IEC61966-2.1", Intent.RELATIVECOLORIMETRIC, true, false);
                        }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    exportOptions = new ExportOptionsSaveForWeb();
                    exportOptions.format = SaveDocumentType.PNG;
                    exportOptions.PNG8 = false; // false = PNG-24
                    exportOptions.transparency = true; // true = transparent
                    exportOptions.interlaced = false; // true = interlacing on
                    exportOptions.includeProfile = true; // false = don't embedd ICC profile
                    document.exportDocument(newFile, ExportType.SAVEFORWEB, exportOptions);
                    document.close(SaveOptions.DONOTSAVECHANGES);
                }
            }
            if (i == fileList.length - 1) {
                alert("All PSD files have been saved as PNG files!");
            }
        }
    }
}

 

 

 

Stephen Marsh
Community Expert
Community Expert
June 20, 2021
quote

And also there is no way to convert all jpg files in one folder to png with photoshop? I tried action but it just gives me psb or jpg again. 

 


By @Marinapomorac

 

 

You can create an action for use with the Batch command.

 

Or use Image Processor Pro or Picture Processor JavaScripts.

Stephen Marsh
Community Expert
Community Expert
June 20, 2021

This quick hack to the original code should work for flattened originals:

 

/* 
Import images to artboards?
https://community.adobe.com/t5/photoshop/import-images-to-artboards/m-p/8430829

Import multiple PNG and JPG files as individual Artboards
https://community.adobe.com/t5/photoshop/import-multiple-png-and-jpg-files-as-individual-artboards/td-p/12125092
*/


// filesToArtboards.jsx - Adobe Photoshop Script
// Version: Modified 2021, Flattened Originals
// Requirements: Adobe Photoshop CC 2015, or higher
// Author: Anton Lyubushkin (nvkz.nemo@gmail.com)
// Website: http://lyubushkin.pro/
// ============================================================================
// Installation:
// 1. Place script in:
// PC: C:\Program Files\Adobe\Adobe Photoshop CC#\Presets\Scripts\
// Mac: <hard drive>/Applications/Adobe Photoshop CC#/Presets/Scripts/
// 2. Restart Photoshop
// 3. Choose File > Scripts > filesToArtboards
// ============================================================================

#target photoshop
app.bringToFront();

// Save the current ruler units and set to pixels
var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;

function cTID(s) {
    return app.charIDToTypeID(s);
}

function sTID(s) {
    return app.stringIDToTypeID(s);
}

function newArtboard(_name, _w, _h) {
    var desc6 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(sTID('artboardSection'));
    desc6.putReference(cTID('null'), ref1);
    var desc7 = new ActionDescriptor();
    desc7.putString(cTID('Nm  '), _name);
    desc6.putObject(cTID('Usng'), sTID('artboardSection'), desc7);
    var desc8 = new ActionDescriptor();
    desc8.putDouble(cTID('Top '), 0);
    desc8.putDouble(cTID('Left'), 0);
    desc8.putDouble(cTID('Btom'), _h);
    desc8.putDouble(cTID('Rght'), _w);
    desc6.putObject(sTID('artboardRect'), sTID('classFloatRect'), desc8);
    executeAction(cTID('Mk  '), desc6, DialogModes.NO);
}

function main() {
    var fileList = app.openDialog("Select your files"),
        delta = 0,
        currentDocWidth = 0;
    if (fileList != null && fileList != "") {
        var doc = app.documents.add(400, 400, 72, "File1");
        for (var i = 0; i < fileList.length; i++) {
            app.open(fileList[i]);

            var idset = stringIDToTypeID("set");
            var desc914 = new ActionDescriptor();
            var idnull = stringIDToTypeID("null");
            var ref474 = new ActionReference();
            var idlayer = stringIDToTypeID("layer");
            var idbackground = stringIDToTypeID("background");
            ref474.putProperty(idlayer, idbackground);
            desc914.putReference(idnull, ref474);
            var idto = stringIDToTypeID("to");
            var desc915 = new ActionDescriptor();
            var idlayer = stringIDToTypeID("layer");
            desc914.putObject(idto, idlayer, desc915);
            executeAction(idset, desc914, DialogModes.NO);

            currentDocWidth = app.activeDocument.width.value;

            newArtboard(app.activeDocument.name, app.activeDocument.width.value, app.activeDocument.height.value);
            app.activeDocument.activeLayer.duplicate(doc, ElementPlacement.INSIDE);
            app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
            if (i > 0) {
                app.activeDocument.activeLayer.translate(delta, 0);
            }

            delta2 = delta + currentDocWidth;
        }
        
        app.runMenuItem(charIDToTypeID("FtOn"));

        var iddelete = stringIDToTypeID("delete");
        var desc733 = new ActionDescriptor();
        var idnull = stringIDToTypeID("null");
        var ref395 = new ActionReference();
        var idlayer = stringIDToTypeID("layer");
        ref395.putName(idlayer, "Layer 0");
        desc733.putReference(idnull, ref395);
        var idlayerID = stringIDToTypeID("layerID");
        var list44 = new ActionList();
        list44.putInteger(5);
        desc733.putList(idlayerID, list44);
        executeAction(iddelete, desc733, DialogModes.NO);

        alert('Done!');
    }
}

main();

// Restore the ruler units
app.preferences.rulerUnits = savedRuler;

 

P.S. The original code didn't specify ruler units (it probably assumed px) and would silently fail with rulers set to percent.

 

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

 

Marinapomorac
Inspiring
June 20, 2021

 

Error. And thank you if you manage to fix this. I have 60 JPG and PNG that I need to use as masks in artboards, I can't do this by hand....

Marinapomorac
Inspiring
June 21, 2021

 

I was trying to track the reported error in my code copy, which is 113 lines of code, vs. your abbreviated code copy of 90 lines. Obviously this makes things harder to find, as the lines are offset. 

 

Perhaps the commercial version will help you:

 

https://exchange.adobe.com/creativecloud.details.15995.uberimport.html

 

It's only $5

 


I copied the entire code before last message, it has 113 lines and that last message I made has the error I get.

 

Error 8800: General Photoshop error occurred. This
functionality may not be available in this version of
Photoshop.
- The command "Set" is not currently available.
Line: 77
-> executeAction(idset, desc914, DialogModes.NO);

 

I will try to reinstall.