Skip navigation
Currently Being Moderated

Save for web filename problems

Apr 7, 2008 1:31 AM

I'm using a script to export layers to PNGs - but the filenames are getting screwed up.

Here's the export function:

function saveForWebPNG(name){
var docName = activeDocument.name;
docName = docName.slice(0,-4);
toWhere = new File(fullPath+"/"+docName+name+".png");
var opts = new ExportOptionsSaveForWeb();
opts.format = SaveDocumentType.PNG;
opts.PNG8 = false;
opts.transparency = true;
opts.interlaced = false;
opts.quality = 100;
activeDocument.exportDocument(toWhere, ExportType.SAVEFORWEB, opts);
}

I end up with things like this:

_generic_filter_failed_disabl#0

when it should be:

_generic_filter_failed_disabled.png

I have a feeling this might be to do with the settings trying to limit it to 32 characters (so they're unix compatible) - but if I change the settings in the Save for web dialog it makes no difference.

TIA,

James
  • Currently Being Moderated
    Community Member
    Apr 7, 2008 6:48 AM
    > I have a feeling this might be to do with the settings trying to limit it to 32 characters

    Yep. It's a hard limit on either the Mac or XP. You may be able to create
    filenames with more than 32 characters, but only the first 32 are significant.
    Back in the earlier MS-DOS days it was far worse.

    >(so they're unix compatible)

    Not a unix problem. You're filenames can be incredibly long on unix.

    >- but if I change the settings in the Save for web dialog it makes no difference.

    I really don't know what that setting controls. I thought it was more like the
    character set or encoding of the filenames. Let me know if you figure it out.

    -X
    --
    for photoshop scripting solutions of all sorts
    contact: xbytor@gmail.com
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    Apr 7, 2008 10:26 AM
    Please try this.
    Goto Save For Web.
    Along side where it says preset there is a flyout menu, select Edit Output Settings, Click "Next" 3 times, you should then see "Filename Compatibility" Untick Mac OS 9.
    This is the one that seems to cause the problem.

    Paul.
    |
    Mark as:
  • Currently Being Moderated
    May 2, 2008 9:28 AM
    seem it no problem in windows !!
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    May 2, 2008 2:53 PM
    I have a script done in applescript which avoids this by truncating the file name before the file is saved, and then renaming the file afterwards. You should be able to do this as well in Javascript.

    In the beginning of your function, check the length of 'name'. Truncate it if it is longer than necessary, then use file object function 'rename' to change the name of the saved file to the original name.
    |
    Mark as:
  • Currently Being Moderated
    Community Member
    May 6, 2008 1:32 PM
    nice.

    I'd suggest as another improvement, that you set your file name 'temp.png' in a loop which checks to see if the file exists, and increments a counter and exits the loop when exists = false.
    |
    Mark as:
  • Currently Being Moderated
    Jul 27, 2009 9:43 AM

    This thread is incredibly useful. Many thanks to all its contributors.

    I've documented the resulting function on my blog in a post titled Photoshop “save for web” JavaScript.

    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)