3 Replies Latest reply on Jun 14, 2010 8:39 AM by Michael L Hale

    How to get the compression type?

    Maria prabhudoss Level 1

      How to get the compression type for tif files using scripting.Kindly advise me.

       

      Thanks.

        • 1. Re: How to get the compression type?
          Michael L Hale Level 5

          THis will get you the compression of the activeDocument.

          var compressionValue = getCompression();
          switch( compressionValue ){
               case 1:
                    var compressionType = "none";
                    break;
               case 5:
                    var compressionType = "lzw";
                    break;
               case 7:
                    var compressionType = "jpg";
                    break;
               case 8:
                    var compressionType = "zip";
                    break;
               default: var compressionType = "unknown";
          }
          alert( compressionType );
          
          function getCompression(){
               try{
                    loadXMPLibrary();
                    var xmp;
                    xmp = new XMPMeta( app.activeDocument.xmpMetadata.rawData );
                    var compression = xmp.getProperty( XMPConst.NS_TIFF, "Compression" ).toString();
                    unloadXMPLibrary();
                    return Number( compression );
               }catch(e){}
          }
          function loadXMPLibrary(){
               if ( !ExternalObject.AdobeXMPScript ){
                    try{
                         ExternalObject.AdobeXMPScript = new ExternalObject
                                                                      ('lib:AdobeXMPScript');
                    }catch (e){
                         alert( ErrStrs.XMPLIB );
                         return false;
                    }
               }
               return true;
          }
          function unloadXMPLibrary(){
             if( ExternalObject.AdobeXMPScript ) {
                try{
                   ExternalObject.AdobeXMPScript.unload();
                   ExternalObject.AdobeXMPScript = undefined;
                }catch (e){
                   alert( ErrStrs.XMPLIB );
                }
             }
          }
          

          You can adapt it using XMPFile to get the compression of tif files not open.

          • 2. Re: How to get the compression type?
            Maria prabhudoss Level 1

            Thanks for your help. This is working fine in Adobe Photoshop CS4. But not working in "Adobe CS version". Could you please advise me how to use this for "Adobe Photoshop CS" version.

            • 3. Re: How to get the compression type?
              Michael L Hale Level 5

              This should work in CS3.

              var xmpString = app.activeDocument.xmpMetadata.rawData;
              var compressionValue = xmpString.match(/<tiff:Compression>(\d)<\/tiff\:Compression>/);
              if( compressionValue !=null ){
                   var compression = Number(compressionValue[1]);
                   switch( compression ){
                        case 1:
                             var compressionType = "none";
                             break;
                        case 5:
                             var compressionType = "lzw";
                             break;
                        case 7:
                             var compressionType = "jpg";
                             break;
                        case 8:
                             var compressionType = "zip";
                             break;
                        default: var compressionType = "unknown";
                   }
                   alert( compressionType );
              }