• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Save PNG with measurements in file name

Explorer ,
Oct 23, 2018 Oct 23, 2018

Copy link to clipboard

Copied

Is it possible to have the file open in Photoshop and use the overall width and height of the canvas size in millimetres saved in the file name? Perhaps it could save to the desktop so then I could drag it into the folder I need. Ideally it would be saved as something like, "123x321" width by height, without any decimal points. Usually I select the canvas and use info to get the measurements and input the details in myself but I make some mistakes this way.

Many thanks in advance

TOPICS
Actions and scripting

Views

572

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Oct 23, 2018 Oct 23, 2018

var pth = "~/Desktop"; // path to save the file, the default save to the desktop, change as needed

var tmp = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.MM;

var w = Math.round(activeDocument.width.value);

var h = Math.round(activeDocument.height.value);

var file = new File(pth+ "/" + w+"x"+h + ".png");

app.preferences.rulerUnits = tmp;

save_as_png(file);

alert("File was saved as\n\n" + file.fsName);

function save_as_png(file, filter, none, comp)

    {

    try {

        if (filter == undef

...

Votes

Translate

Translate
Adobe
Contributor ,
Oct 23, 2018 Oct 23, 2018

Copy link to clipboard

Copied

This is an example script that can do what you like.

It keeps the current name, so you can tweak that as required:

#target photoshop

var strtRuler = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

  

var doc = app.activeDocument;

var dName = doc.name;

var dNameNoExt = dName.replace (".png","");

try{var dPath = doc.path;}

catch(e){var dPath = Folder.selectDialog( "Where would you like to save the image?");};

app.preferences.rulerUnits = strtRuler

   

var aFolder= Folder (dPath + "/" + "Saved")

if (!aFolder.exists) aFolder.create();

var pngOptions = new PNGSaveOptions();

with (pngOptions) {

    embedColorProfile = true;

    compression = 6

    interlaced = false

    };

var dDims = [doc.height] + [doc.width];

doc.saveAs((File(aFolder + "/ " + dNameNoExt + dDims)),pngOptions,true);  

doc.close(SaveOptions.DONOTSAVECHANGES);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 23, 2018 Oct 23, 2018

Copy link to clipboard

Copied

var pth = "~/Desktop"; // path to save the file, the default save to the desktop, change as needed

var tmp = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.MM;

var w = Math.round(activeDocument.width.value);

var h = Math.round(activeDocument.height.value);

var file = new File(pth+ "/" + w+"x"+h + ".png");

app.preferences.rulerUnits = tmp;

save_as_png(file);

alert("File was saved as\n\n" + file.fsName);

function save_as_png(file, filter, none, comp)

    {

    try {

        if (filter == undefined) filter = "PNGFilterAdaptive";

        if (none == undefined) none = true;

        if (comp == undefined) comp = 9;

        var d = new ActionDescriptor();

        var d1 = new ActionDescriptor();

        if (none)

            d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceNone"));

        else

            d1.putEnumerated(stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceType"), stringIDToTypeID("PNGInterlaceAdam7"));

        d1.putEnumerated(stringIDToTypeID("PNGFilter"), stringIDToTypeID("PNGFilter"), stringIDToTypeID(filter));

        d1.putInteger(stringIDToTypeID("compression"), comp);

        d.putObject(stringIDToTypeID("as"), stringIDToTypeID("PNGFormat"), d1);

        d.putPath(stringIDToTypeID("in"), file);

        d.putBoolean(stringIDToTypeID("copy"), true);

        executeAction(stringIDToTypeID("save"), d, DialogModes.NO);

        }

    catch (e) { alert(e); throw(e); }

    }

upd. was edited

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2018 Oct 23, 2018

Copy link to clipboard

Copied

LATEST

Thanks so much guys. It was a bit of a struggle for me to tweek varDale's script even though it was really good. Thanks again, I really appreciate it

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines