5 Replies Latest reply on Mar 7, 2014 3:37 AM by c.pfaffenbichler

    Photoshop Script Question

    fuzz.royale

      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?

        • 1. Re: Photoshop Script Question
          c.pfaffenbichler Level 9

          What do you mean exactly?

          Apply an existing Clipping Path as transparency?

          • 2. Re: Photoshop Script Question
            fuzz.royale Level 1

            Well, I have TIF files with good clipping paths around the image, but the background is white. I would like the image over a transparent background as a PNG file. I have hundreds of TIFs to convert to PNG with transparent backgrounds, so a script would be very helpful, to say the least! The script would need to take the selection inside the clipping poath and save it over a transparent background. Hope this helps!

            • 3. Re: Photoshop Script Question
              JJMack Most Valuable Participant

              fuzz.royale wrote:

               

              Well, I have TIF files with good clipping paths around the image, but the background is white. I would like the image over a transparent background as a PNG file. I have hundreds of TIFs to convert to PNG with transparent backgrounds, so a script would be very helpful, to say the least! The script would need to take the selection inside the clipping poath and save it over a transparent background. Hope this helps!

              If all the tif files have a good path around the subject and the path have the same name you may be able to do what you want with a simple action to be used with the Image Processor Pro script to save PNG files.  All the action would need do to to flatten the document being work on in case the tiff is layered. Convert the Background to a normal layer. Load the path as a selection the add it as the layer mask.

               

              White can easily be removed from an image with an action.  However white area in the subject will also be removed add a empty  load the path as a selection and fill with white.   However white adjacent to a  subject is normally a gray shade so there will be some fringe areas.

               

              http://forums.adobe.com/message/6079459#6079459#6079459

              • 4. Re: Photoshop Script Question
                c.pfaffenbichler Level 9

                You are aware that if the images’s backgrounds have be filled with white based on inverted anti-aliased Selections based on the Clipping Paths then the images’ edge pixels are damaged?

                 

                Do the tiffs only have one Layer?

                • 5. Re: Photoshop Script Question
                  c.pfaffenbichler Level 9

                  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 );*/

                  };