0

I'm using a plugin to export my pngs (https://www.fnordware.com/superpng/) Anyone knows how I can replicate the Export Layers to files functionality that comes with photoshop but export as SuperPNG?

There is export options documentation but only includes the default photoshop formats...

Thanks in advance!

1
  • I think there might not be a lot of demand for that when there are so many standalone applications for image compression. I often use ImageOptim. It's a little manual (1 more step in the workflow) but for a lot of things, it doesn't really matter. I don't know where you're using the images, but it may also be possible for you to automatically compress on build or whatever.
    – Joonas
    Commented Jan 30, 2019 at 8:20

2 Answers 2

0

Here's the script I use to save quantified pngs (it uses SuperPNG plugin you mentioned). There're some options in there that I didn't test (with // ??) but by default it saves a png with max quality and transparency. It also checks if you have SuperPNG installed.

exportSuperPng(
{
    path: "/C/Users/Sergey Kritskiy/Desktop/temp", // required
    name: "test-png", // default: document name
    quality: 100, // default: 100 (Highest) 82 is High
    transparency: true, // default: true
})

function exportSuperPng(data)
{
    if (data == void(0)) return false;
    if (data.path == void(0)) return false;
    if (data.quality == void(0)) data.quality = 100;
    if (data.name == void(0)) data.name = activeDocument.name;
    if (data.transparency == void(0)) data.transparency = true;
    if (!getSuperPngInfo()) return false;

    var desc = new ActionDescriptor();
    var descSPng = new ActionDescriptor();
    descSPng.putInteger(charIDToTypeID('pngC'), 9); // ??
    descSPng.putInteger(charIDToTypeID('pngF'), 248); // ??
    descSPng.putInteger(charIDToTypeID('pngS'), 0); // ??
    descSPng.putBoolean(charIDToTypeID('pngQ'), true); // ??
    descSPng.putInteger(charIDToTypeID('pngq'), data.quality); // quality
    descSPng.putEnumerated(charIDToTypeID('pngA'), charIDToTypeID('alfT'), data.transparency ? charIDToTypeID('alfT') : charIDToTypeID('alfN'));
    descSPng.putBoolean(charIDToTypeID('pngX'), false);
    descSPng.putBoolean(charIDToTypeID('pngI'), false); // ??
    descSPng.putBoolean(charIDToTypeID('pngM'), false); // ??
    desc.putObject(charIDToTypeID('As  '), stringIDToTypeID('fnord SuperPNG'), descSPng);
    desc.putPath(charIDToTypeID('In  '), new File(data.path + "/" + data.name + ".png"));
    desc.putInteger(charIDToTypeID('DocI'), 475);
    desc.putEnumerated(stringIDToTypeID('saveStage'), stringIDToTypeID('saveStageType'), stringIDToTypeID('saveSucceeded'));
    executeAction(charIDToTypeID('save'), desc, DialogModes.NO);

    function getSuperPngInfo()
    {
        var sysInfo = app.systemInformation.split("\n");
        for (var i = sysInfo.length - 1; i >= 0; i--)
        {
            if (sysInfo[i].indexOf('SuperPNG') != -1)
            {
                return true
            }
        }
        return false
    }
};
2
  • I tried your script but it is throwing an error of: Error 8800: General Photoshop error occurred. This functionality may not be available in this version of Photoshop. -Could not save a copy as "test-png.png" because the file could not be found. Line: 33 -> executeAction(charIDToTypeID("save"), desc, DialogModes.NO); I am running Photoshop 2022, I also made a png file with "test-png" name but still get the error. I also tried it with Photoshop CC 2019 and get the same error. Is the script able to still work with current versions? Not sure if I am doing something wrong.. Commented Jul 9, 2022 at 1:37
  • @SuperUser69420 when you just say "it doesn't work" it's impossible to say why. My guess is path is wrong, not the filename Commented Jul 10, 2022 at 6:59
0

Leaving it here with extra options if anyone needs

exportSuperPng(
{
    path: Folder.desktop, // required
    name: "test-png", // default: document name
    quality: 100, // default: 100 (Highest) 82 is High
    transparency: true, // default: true
    saveMetadata: false,
    cleantransparent:true,
    pInterlacted:false
})

function exportSuperPng(data, path, name)
{
    data.path = path;
    data.name = name;

    if (data == void(0)) return false;
    if (data.path == void(0)) return false;
    if (data.quality == void(0)) data.quality = 100;
    if (data.name == void(0)) data.name = activeDocument.name;
    if (data.transparency == void(0)) data.transparency = true;
    if (data.saveMetadata == void(0)) data.saveMetadata = false;
    if (data.cleantransparent == void(0)) data.cleantransparent = true;
    if (data.pInterlacted == void(0)) data.pInterlacted = false;
    if (!getSuperPngInfo()) return false;

    var desc = new ActionDescriptor();
    var descSPng = new ActionDescriptor();
    descSPng.putInteger(charIDToTypeID('pngC'), 9); // ??
    descSPng.putInteger(charIDToTypeID('pngF'), 248); // ??
    descSPng.putInteger(charIDToTypeID('pngS'), 0); // ??
    descSPng.putBoolean(charIDToTypeID('pngQ'), true); // ??
    descSPng.putInteger(charIDToTypeID('pngq'), data.quality); // quality
    descSPng.putEnumerated(charIDToTypeID('pngA'), charIDToTypeID('alfT'), data.transparency ? charIDToTypeID('alfT') : charIDToTypeID('alfN'));
    descSPng.putBoolean(charIDToTypeID('pngX'), data.cleantransparent);
    descSPng.putBoolean(charIDToTypeID('pngI'), data.pInterlacted);
    descSPng.putBoolean(charIDToTypeID('pngM'), data.saveMetadata);
    desc.putObject(charIDToTypeID('As  '), stringIDToTypeID('fnord SuperPNG'), descSPng);
    desc.putPath(charIDToTypeID('In  '), new File(data.path + "/" + data.name + ".png"));
    desc.putInteger(charIDToTypeID('DocI'), 475);
    desc.putEnumerated(stringIDToTypeID('saveStage'), stringIDToTypeID('saveStageType'), stringIDToTypeID('saveSucceeded'));
    executeAction(charIDToTypeID('save'), desc, DialogModes.NO);

    function getSuperPngInfo()
    {
        var sysInfo = app.systemInformation.split("\n");
        for (var i = sysInfo.length - 1; i >= 0; i--)
        {
            if (sysInfo[i].indexOf('SuperPNG') != -1)
            {
                return true
            }
        }
        return false
    }
};

exportSuperPng();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.