Photoshop scripting, export to png?

I use the following code:
function SavePNG(saveFile){
  var opts = new ExportOptionsSaveForWeb();
  opts.format = SaveDocumentType.PNG;
  opts.PNGB = true;
  opts.quality = 100;
  pngFile = new File(saveFile);
  opts.includeProfile = true;
  app.activeDocument.exportDocument(pngFile, ExportType.SAVEFORWEB, opts);
It almost workable, but it works with fully visible or fully invisible areas only. For example if I have a transparent layer and add a second transparent layer with a red rect with opacity 50%, then I will got an image where the transparency of this rect is 100% (fully visible).
How to solve this problem? I use Photoshop CS6 (Mac OS version).

In ESTK check out Help > Object Model Viewer, select Photoshop and look up »ExportOptionsSaveForWeb«.
Also you should be able to find examples in the Photoshop Scripting Forum.

Similar Messages

  • Photoshop Script: Export Layer To File

    Hi
    I have set up an action to  use "Export Layer To Files" to save out  multipile jpg, and I have noticed the file compression is allot larger compared to the, Save for web option. Is there anyway I can use Export Layer To Files in an action, but then use the Save for web option to get better compression for the final file export?

    The "Export Layer To Files"  script seems to be a plugin script therefore it records the setting use in it dialog into an action step when recorded into an action. Thus when the action is played the "Export Layer To Files" script step  will bypass displaying its "Export Layer To Files" dialog and use the setting it recorded into your action step. So you must have selected save jpeg and set a high quality jpeg setting in its dialog when you recorded the action. If you re-record the action step and uncheck include ICC profile and set a low jpeg quality setting.  The jpeg files saved will be smaller in the future.   The Jpeg quality setting influences how  compression is done.  Low quality setting loose more image quality than high settings but the output file size is smaller with lower values. Save for web you can reduce output size also by saving lower quality image additionally you can also strip all image meta-data and reduce the  image size using interpolation.

  • How can I get the script Export Layers to Files to export compressed pngs?

    I would love to be able to take advantage of Photoshop's compressed png when using the script Export Layers to Files. I there a way I could modify the script to do this?
    TIA!!!
    ========================
    I found it ... I needed to add a line to the pngSaveOptions (around line #886) ...
                var saveFile = new File(exportInfo.destination + "/" + fileNameBody + ".png");
                pngSaveOptions = new PNGSaveOptions();
                pngSaveOptions.interlaced = false;
                // trying to compress png files
                pngSaveOptions.compression = 9;
                docRef.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
                break;
    =========================

    It does. The standalone XML Export was only offered by itself
    in the
    registration incentives. Sorry.
    Nancy Gill
    Adobe Community Expert
    Author: Dreamweaver 8 e-book for the DMX Zone
    Co-Author: Dreamweaver MX: Instant Troubleshooter (August,
    2003)
    Technical Editor: DMX 2004: The Complete Reference, DMX 2004:
    A Beginner''s
    Guide, Mastering Macromedia Contribute
    Technical Reviewer: Dynamic Dreamweaver MX/DMX: Advanced PHP
    Web Development
    "neilcreagh" <[email protected]> wrote in
    message
    news:f4rsrt$ptf$[email protected]..
    > I've just purchased Dreamweaver CS3 and, after
    registering, the email sent
    > offered me a free gift. I chose the free font. Another
    option is the
    > Dreamweaver XML Export Extension for Spry and I would
    like to purchase
    > this (it
    > stated the value at ?15) but I can't find it anywhere?
    >
    > The interaktonline website says that its functionality
    has been included
    > in
    > the Dreamweaver Developer Toolbox - but does this mean
    that I have to
    > purchase
    > the entire toolbox?
    >

  • CS5 Photoshop Scripts Error: Export Layers to Files...

    Hey Folks,
    I'm banging my head against the wall trying to figure out why I can't use the script: Export Layers to Files...
    I am recieving this error messages in my attempt:
    I have ran the Adobe updater and made sure everything is current.
    I restarted my magic toster twice after the update.
    I even tried a basic psd with 2 layers in an effort to determine if it was the working psd file itself... No luck.
    So I am convinced now that there may be a bug.
    Does anyone have any insight or workarounds for this solution?
    Thank you all in advance.
    John

    Jeffrey,
    Thanks for your response.
    It's the original script that shipped stock with CS5.
    Get this...
    I switched from 32 bit mode back into 64 and restarted the program.
    Opened my psd and tried again...
    No error this time, but this is what I get:
    Nothing!
    So racked on this one dude...

  • Photoshop Script  Black and White Raster to Vector

    I do not have AI Adobe for I do not want to spend the money and have to learn an other complex Adobe application. I'm no artist either.  However at rimes I wanted  to have AI live trace feature to change black and white line drawing into vector graphics. AI creates EPS files with embedded vectors. And can export the vector to Photoshop.  Though Photoshop opens EPS as raster layers I find that EPS file created from tracing black and white lines and artwork with programs like potrace that use curves to create black vector shapes. That when these are opened in Photoshop as Black layer with transparency. When these layers transparency are loaded as a selection and the selections converted to path. I find the path are extremely good.
    Potrace is a cross platform open source program packages available for many operating systems. Windows (32 bit) and (64 bit), Mac OS X (Intel), Mac OS X (universal),Linux (32 bit) and (64 bit), Linux (Alpha), Linux (Sparc64), Sun Solaris (Sparc), Sun Solaris (i386), Sun Solaris (x86_64), FreeBSD (i386), NetBSD (i386), OpenBSD (i386), AIX and AROS (i386). Potrace is a command line command. So it can be use started with options and passed a file from bat files and scripts. Potrace requires No instillation. All the needed potrace requited files just need to be place into a folder and potrace run from that folder as the current directory.
    So a created a Photoshop script that more or less uses potrace like a Photoshop Plug. The script define a custom shape for the current active document using potrace and add a new shape layer using the new defined custom shape as the top layer. The script also toggle off the other visible layers so you just see the shape layer.  You can use alt click on the shape layer visibility icon to toggle the other layer visibility so you can see how well it matches the document.
    I'm a windows user so the Photoshop script I wrote though in javascript will most likely only run on a windows platform because of my use of windows features its command line start command and file system conventions. I'm quite sure a Mac variant could created. Here is screen capture showing how well the defile shape  matches up and a link to the script. You would need to download potrace to use it and fix the vars in the script that point to potrace. http://www.mouseprints.net/old/dpr/potrace.jsx

    Good day!
    Please check out the chapter "Automation" in the Reference.
    If the task can be recorded as a plain Action it can be applied to multiple Files for example via File > Automate > Batch or File > Scripts > Image Processor.
    Regards,
    Pfaffenbichler

  • Lightroom and Photoshop scripts

    Is there an easy way from lightroom to export a file to a photoshop script (e.g. xxx.jsx) such that the desired action in photshop can be scripted ?  I know I can export to photoshop and edit, then run the script -- just wondering if this can be done in one step

    I don't recall it being discussed before. However, given that Lightroom uses Bridge Talk to communicate with Photoshop it might be worth asking the question over on the Bridge Scripting forum http://forums.adobe.com/community/bridge/bridge_scripting or Lightroom SDK forum http://forums.adobe.com/community/lightroom/lightroom_sdk

  • Can i invoke Photoshop Scripting in web page?

    Can i invoke Photoshop Scripting in web page?

    hmmm...
    On the page in admin,we should have a button to export the  item to Photoshop.  A PSD of the entire should be assembled from the elements of the XML. This means that the text leading and tracking will need to be translated from server settings to Photoshop settings. Font sizes should also match.

  • Batch Export as PNG

    Hello, i'm having dreadful trouble exporting a batch of AIs to PNG (using illustrator CS4).
    It seemed really obvious to record export>PNG>relevant setting as an action and then run that on the whole folder.
    The trouble is that the action, when run as a batch (and only when run as a batch) skips the whole export step. it open the AI fine, runs through the action very quickly, and then fails to write the PNG.
    what's more, i also tried this on a colleagues machine and his did exactly the same, so i'm thinking that it's me missing something obvious.
    as a workaround i turned the dialogues on, but this kind of defeats the object.
    any help would be very greatly appreciated.
    cheers
    Jez

    You might try this
    ADOBE SYSTEMS INCORPORATED
    Copyright 2005 Adobe Systems Incorporated
    All Rights Reserved
    NOTICE:  Adobe permits you to use, modify, and
    distribute this file in accordance with the terms
    of the Adobe license agreement accompanying it. 
    If you have received this file from a source
    other than Adobe, then your use, modification,
    or distribution of it requires the prior
    written permission of Adobe.
    ExportDocsAsPNG24.jsx
    DESCRIPTION
    This sample gets files specified by the user from the
    selected folder and batch processes them and saves them
    as PDFs in the user desired destination with the same
    file name.
    // Main Code [Execution of script begins here]
    // uncomment to suppress Illustrator warning dialogs
    // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
    var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pngExportOpts;
    // Select the source folder.
    sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );
    // If a valid folder is selected
    if ( sourceFolder != null )
        files = new Array();
        fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );
        // Get all files matching the pattern
        files = sourceFolder.getFiles( fileType );
        if ( files.length > 0 )
            // Get the destination to save the files
            destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PNG files.', '~' );
            for ( i = 0; i < files.length; i++ )
                sourceDoc = app.open(files[i]); // returns the document object
                // Call function getNewName to get the name and file to save the pdf
                targetFile = getNewName();
                // Call function getPNGOptions get the PNGExportOptions for the files
                pngExportOpts = getPNGOptions();
                // Export as PNG
                sourceDoc.exportFile( targetFile, ExportType.PNG24, pngExportOpts );
                sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
            alert( 'Files are saved as PNG in ' + destFolder );
        else
            alert( 'No matching files found' );
    getNewName: Function to get the new file name. The primary
    name is the same as the source file.
    function getNewName()
        var ext, docName, newName, saveInFile, docName;
        docName = sourceDoc.name;
        ext = '.png'; // new extension for png file
        newName = "";
        for ( var i = 0 ; docName[i] != "." ; i++ )
            newName += docName[i];
        newName += ext; // full png name of the file
        // Create a file object to save the png
        saveInFile = new File( destFolder + '/' + newName );
        return saveInFile;
    getPNGOptions: Function to set the PNG saving options of the
    files using the PDFSaveOptions object.
    function getPNGOptions()
        // Create the PDFSaveOptions object to set the PDF options
        var pngExportOpts = new ExportOptionsPNG24();
        // Setting PNGExportOptions properties. Please see the JavaScript Reference
        // for a description of these properties.
        // Add more properties here if you like
        pngExportOpts.antiAliasing = true;
        pngExportOpts.artBoardClipping = false;
        //pngExportOpts.horizontalScale = 100.0;
        //pngExportOpts.matte = true;
        //pngExportOpts.matteColor = 0, 0, 0;
        pngExportOpts.saveAsHTML = false;
        pngExportOpts.transparency = true;
        //pngExportOpts.verticalScale = 100.0;
        return pngExportOpts;
    Copy into a text editor and save as a .jsx file and place in the presets>scripts folder.

  • Scripts / Export Layers to Files / Include Background Layer

    Running the script Export Layers to files.
    Need to keep one layer on that is applied to all the layers (I have a stroke on the top layer I would like applied to all the images that are saved out.)
    How do I modify the script for this?
    Thanks!
    Ken

    Adapting that Script might be somewhat difficult as it is pretty bulky.
    But if its always the topmost layer thats supposed to stay visible and You know which format You want to save the resulting files to beforehand something much smaller may suffice.
    You might try this, but I havent tested it extensively:
    #target photoshop;
    var myDocument = app.activeDocument;
    // get the name and location;
    var docName = myDocument.name;
    var basename = docName.match(/(.*)\.[^\.]+$/)[1];
    var docPath = myDocument.path;
    // get the artlayers and remove the topmost;
    var allArtLayers = collectLayers(myDocument);
    var theTopmost = allArtLayers.pop();
    // hide all but the topmost layer;
    for (var n = 0; n < allArtLayers.length; n++ ) {
       allArtLayers[n].visible = false
    for (var m = 0; m < allArtLayers.length; m++ ) {
    // show the layer;
       allArtLayers[m].visible = true;
    // tiff options;
       tifOpts = new TiffSaveOptions();
       tifOpts.embedColorProfile = true;
       tifOpts.imageCompression = TIFFEncoding.TIFFLZW;
       tifOpts.alphaChannels = false;
       tifOpts.byteOrder = ByteOrder.MACOS ;
       tifOpts.layers = true;
    // duplicate the image;
       var thecopy = myDocument.duplicate (thecopy, true);
    // save copy;
       thecopy.saveAs((new File(docPath+"/"+basename+" "+allArtLayers[m].name+".tif")),tifOpts,true);
       thecopy.close(SaveOptions.DONOTSAVECHANGES);
    // hide the layer again;
       allArtLayers[m].visible = false
    //thats it; thanks to xbytor;
    ////// collect all artlayers //////
    function collectLayers (theParent) {
       if (!allArtLayers) {
          var allArtLayers = new Array}
       else {};
       for (var m = theParent.layers.length - 1; m >= 0;m--) {
          var theLayer = theParent.layers[m];
    // apply the funtion to layersets;
          if (theLayer.constructor == ArtLayer) {
             allArtLayers = allArtLayers.concat(theLayer)
          else {
             allArtLayers = allArtLayers.concat(collectLayers(theLayer))
       return allArtLayers

  • Photoshop Script Question

    Is there a Photoshop script to remove the white background from TIF images that already have good clipping paths, and then save file as PNG?

    This should do some of what you are after.
    The Script just flattens the file and applies a Layer Mask, then saves a png but leaves the original file like that.
    // 2014, use it at your own risk;
    #target photoshop;
    if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    // getting the name and location;
    var docName = myDocument.name;
    var basename = docName.match(/(.*)\.[^\.]+$/)[1];
    //getting the location;
    var docPath = myDocument.path;
    // check paths;
    for (var m = 0; m < myDocument.pathItems.length; m++) {
    var thePath = myDocument.pathItems[m];
    if (thePath.kind == PathKind.CLIPPINGPATH) {
    thePath.makeSelection(0, true, SelectionType.REPLACE);
    myDocument.flatten();
    myDocument.layers[0].isBackgroundLayer = false;
    addLayerMask ();
    // save png;
    savePNG (myDocument, docPath, basename, "_a");
    ////// function to png //////
    function savePNG (myDocument, docPath, basename, theSuffix) {
    // weboptions;
    var webOptions = new ExportOptionsSaveForWeb();
    webOptions.format = SaveDocumentType.PNG;
    webOptions.PNG8 = false;
    webOptions.transparency = true;
    webOptions.interlaced = 0;
    webOptions.includeProfile = false;
    webOptions.optimized = true;
    myDocument.exportDocument(new File(docPath+"/"+basename+theSuffix+".png"), ExportType.SAVEFORWEB, webOptions);
    ////// add layer mask //////
    function addLayerMask () {
    var idMk = charIDToTypeID( "Mk  " );
    var desc168 = new ActionDescriptor();
    var idNw = charIDToTypeID( "Nw  " );
    var idChnl = charIDToTypeID( "Chnl" );
    desc168.putClass( idNw, idChnl );
    var idAt = charIDToTypeID( "At  " );
    var ref99 = new ActionReference();
    var idChnl = charIDToTypeID( "Chnl" );
    var idChnl = charIDToTypeID( "Chnl" );
    var idMsk = charIDToTypeID( "Msk " );
    ref99.putEnumerated( idChnl, idChnl, idMsk );
    desc168.putReference( idAt, ref99 );
    var idUsng = charIDToTypeID( "Usng" );
    var idUsrM = charIDToTypeID( "UsrM" );
    var idRvlS = charIDToTypeID( "RvlS" );
    desc168.putEnumerated( idUsng, idUsrM, idRvlS );
    executeAction( idMk, desc168, DialogModes.NO );
    /*// unlink;
    // =======================================================
    var idsetd = charIDToTypeID( "setd" );
        var desc10 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref3 = new ActionReference();
            var idLyr = charIDToTypeID( "Lyr " );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref3.putEnumerated( idLyr, idOrdn, idTrgt );
        desc10.putReference( idnull, ref3 );
        var idT = charIDToTypeID( "T   " );
            var desc11 = new ActionDescriptor();
            var idUsrs = charIDToTypeID( "Usrs" );
            desc11.putBoolean( idUsrs, false );
        var idLyr = charIDToTypeID( "Lyr " );
        desc10.putObject( idT, idLyr, desc11 );
    executeAction( idsetd, desc10, DialogModes.NO );*/

  • Illustrator CS4 crops my artwork when exporting to png

    Illustrator CS4 crops my artwork when exporting to png (it always crops on the right side). It doesn't happen everytime but often enough to be annoying. Sometimes centering my artwork in the artboard solves the problem but not always. Do you have any idea why it's happening, and what I can do to avoid that problem?
    (See the attached png)

    @Jacob & Mylenium: I don't have any stroked path in my artwork. I've tried to add a no fill/no stroke rectangle (same size as my artwork and then a bit bigger) but it didn't work.
    Your advices gave me an idea though: I've added a filled rectangle slightly bigger than my artwork, centered it and dropped its opacity to 0%, it worked.
    I'm glad I know that trick now, because even when my artwork wasn't badly cropped, it was touching the edges of the picture (png). Then I had to open it in Photoshop and increase the canvas size in order to leave some transparent space between the artwork and the edges of the picture. Now I can do that in Illustrator
    Thanks a lot for your help !

  • Exporting to PNG, Stroke Weight not Scaling with Export Scale

    Hi there
    I am having some issues exporting illustrator documents to multiple sizes of PNG.
    I am actually scripting this, but the issue seems to be more general - hence the posting here.
    If you export a PNG through the web and devices tool:
    File->Save for Web & Devices
    And you scale the image by 50%, the line weight does not seem to be scaled with the export scale.
    In Illustrator->Preferences->General I have Scale Strokes and Effects ticked.
    This problem is also apparent when scaling a scripted PNG export through the ExportOptionsPNG24 class.
    Is there anything I am missing please - or does anyone know of workarounds?
    Thank you

    Thanks for looking into it Kurt.
    I can't post the illustrator file in question to the forum.
    And, you are right, when I aim to make a demo file from scratch I can't reproduce the problem either.
    I am having this difficulty on multiple files though, and they are all quite complex.
    I will aim to try and make a file that shows the problem.
    The files in question may have symbols that were created in much earlier versions of Illustrator.
    I'm not sure if that could do it.
    The sequence above shows the output as I export via script to successively smaller scales.
    This is by setting the horizontalScale and verticalScale in ExportOptionsPNG24.
    I see the same results if scaling in Save for Web & Devices.

  • Execute photoshop script via illustrator cs5

    Hi
    Is it possible to execute Photoshop script via illustrator
    I have 2 different script
    script 1 work in illustrator with eps file and export as jpeg
    script 2 where i want to trim the exported jpeg for illustrator in photoshop and save it back
    I have 2 differnt script with me
    can anyone help me to club both and run at same time..
    Thank you
    Appu

    use BridgeTalk to have Illustrator talk to Photoshop, here's a sample by Mark
    Illustrator script to open file in Photoshop
    or use inter app communication
    open PS, open a document
    // start your illustrator script
    var Aidoc = app.activeDocument;
    continue with your script
    // when ready, call your photoshop script
    // this sample alerts the active document name and closes it
    photoshop.executeScript("alert('document name: ' + app.activeDocument.name); app.activeDocument.close()");

  • Save error when exporting to PNG in Illustrator using a Macbook with Yosemite

    Anybody experience the issue of png being saved with "/" in the beginning of the file name when exporting to png in Illustrator? This only happens when I use my mac not my PC.
    Due to the save error my PC cannot identify the files and when the files are linked in Indesign they are not copied when packaging the indesign file.
    Any advice on the issue are most appreciated

    I don't have a lot of experience with this kind of problem, but the first thing I'd check is the parameter block you're passing the action call. I don't know why it would matter if the dialog appeared or not, unless the export settings block wasn't being filled in with everything it needs?
    You might try recording an export you perform manually via the action palette, and then saving it to a file. You can open it up manually and compare it (even if it's a binary block) to what you're doing in code. You might spot something that way.
    I don't know what else to suggest though. It's unlikely to be an SDK bug, though it could be a bug in the action-aware part of the exporter.

  • Save error when exporting to Png i Illustrator

    Anybody experience the issue of png being saved with "/" in the beginning of the file name when exporting to png in Illustrator. This only happens when I use my mac not my PC.
    Due to the save error my PC cannot identify the files and when the files are linked in Indesign they are not copied when packaging the indesign file.
    Any advice on the issue are most appreciated

    Hi,
    I am moving your posting to Illustrator Forum from Acrobat.com Forum.
    Thank you
    Hisami

Maybe you are looking for

  • To ignore negative values

    Hi ALL, In my report there are total 3 fields - Region, Director and Net Val. Now Directors are Persons to whom Project Mangers are reportiong. Here user wants to see Net value based on region which are positives. Now If I take the above three fields

  • Consistent crashing when rendering using Keylight in AE CS6

    Ok, so the subject says what is happening. I have tested my RAM several times, and I have even managed to get through the entire render without crashing with 16gb. But when I go over 16gb, it doesn't last longer than 10 minutes rendering. Here is the

  • Multiple instances of crystal report

    I have a report with 40 instances in infoview. Wherever we need to chage in the report level, I have to reschedule all the 40 instances, which is tedious. In BO, do they have anything, so that the instances sholud point the new report? Thanks, Sagari

  • Set screen resolution, and full screen view mode (F11)

    Hi, I have a jsp page which only looks right in 1280x1024. Can I write some kind of code to set the browser to always be 1280x1024 and the view mode to be full screen regardless of the client's setting? I would like to thank all for responding to my

  • How to stop collecting CIF queues in SAP ECC.

    We had implemented SAP Plug-In CIF for live data transfer between R/3 and APO ., now that we stopped using APO,  we want stop collecting data in CIF relevant queues in R/3 system. Deleting or changing RFC destinations didn't help as queues are still