Question

I'm trying to add a layer to some images and then save them.

The problem is that many images have whitespace in the name. When I try to save the whitespaces are replaced with "-", but I want mantain the same name.

For example an image called "Google Analytics.png" become "Google-Analytics.png". But I need to preserve the name without that extra "-".

My code:

function SavePNG(saveFile){
    var file = new File(saveFile);

    var pngOpts = new ExportOptionsSaveForWeb; 
    pngOpts.format = SaveDocumentType.PNG
    pngOpts.PNG8 = false; 
    pngOpts.transparency = false; 
    pngOpts.interlaced = false; 
    pngOpts.quality = 100;
    $.writeln(file)
    app.activeDocument.exportDocument(file,ExportType.SAVEFORWEB,pngOpts); 
}
Était-ce utile?

La solution

Try using saveAs instead of exportDocument; it'll respect the name of the file you give it. The options are yours to change:

var myfile = "C:\\temp\\Google Analytics.png";

SavePNG(saveFile)

function savePNG(saveFile)
{
  // save out the image
  var pngFile = new File(filepath);
  pngSaveOptions = new PNGSaveOptions();
  pngSaveOptions.embedColorProfile = true;
  pngSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
  pngSaveOptions.matte = MatteType.NONE;
  pngSaveOptions.quality = 1;

 activeDocument.saveAs(pngFile, pngSaveOptions, false, Extension.LOWERCASE);
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top