• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

get tiff compression type

New Here ,
Apr 08, 2015 Apr 08, 2015

Copy link to clipboard

Copied

Hi,

I want to a series of  TIFF files compression [LZW or NONE] in a folder.

Can anyone help me in this . . .

The Script goes here:

#target photoshop

var myInputFolder = Folder.selectDialog ("INPUT");

if(myInputFolder!=null){

    var myFiles = myInputFolder.getFiles(/\.(tif)$/i);

    for(var fileIndex=0;fileIndex<myFiles.length;fileIndex++)

    {

        var currentFile = myFiles[fileIndex];

        if(currentFile instanceof File)

        {

                if(currentFile.hidden) continue;

                    var doc = app.open(currentFile);

                   

                    if(doc.encoding != TIFFEncoding.TIFFLZW)

                    {

                        //Here I want to write code for checking compression of TIFF.

                         alert("Compression should be NONE")

                     }

                    }

                }

            }

Thanks In Advance,

Suresh.N.

TOPICS
Actions and scripting

Views

506

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Enthusiast ,
Apr 09, 2015 Apr 09, 2015

Copy link to clipboard

Copied

Here is a function to get the compression.

#target photoshop;

var file = File("/j/testing/tifs/11.tif");

alert(getTifCompession(file));

function getTifCompession(file){

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

var xmpf = new XMPFile(file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);

var xmp = xmpf.getXMP();

try{

var comp = xmp.getProperty( XMPConst.NS_TIFF, "Compression" ).toString();

var result = '';

switch( Number(comp) ){ 

     case 1:  result = "none"; break; 

     case 5:  result = "lzw";  break;

     case 7:  result = "jpg";  break;

     case 8:  result =  "zip";  break;

     default: result =  "unknown"; 

}

return result;

}catch(e){return undefined;}

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 09, 2015 Apr 09, 2015

Copy link to clipboard

Copied

Hi,

Thanks for the reply.

But I want to Check number of TIFF files in a folder (For E.g 100 files). If the TIFF compression not equal to NONE It should give Error. Script is Working with the single file.

I tried for Multiple files like this. But results nothing. Can you help you in this.

Code goes here:

#target photoshop

var myInputFolder = Folder.selectDialog ("INPUT");

if(myInputFolder!=null){

    var myFiles = myInputFolder.getFiles(/\.(tif)$/i);

    for(var fileIndex=0;fileIndex<myFiles.length;fileIndex++)

    {

        var currentFile = myFiles[fileIndex];

        if(currentFile instanceof File)

        {

                if(currentFile.hidden) continue;

                    var file = app.open(currentFile);

                                                          

function getTifCompession(file){ 

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); 

var xmpf = new XMPFile(file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ); 

var xmp = xmpf.getXMP(); 

try{ 

var comp = xmp.getProperty( XMPConst.NS_TIFF, "Compression" ).toString(); 

var result = ''; 

switch( Number(comp) ){   

     case 1:  result = "none"; break;   

     case 5:  result = "lzw";  break; 

     case 7:  result = "jpg";  break; 

     case 8:  result =  "zip";  break; 

     default: result =  "unknown";   

}  

return result; 

}catch(e){return undefined;} 

}; 

alert(getTifCompession(file));

                    }

                }

            }

Thanks in Advance,

Regards,

Suresh.N.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 09, 2015 Apr 09, 2015

Copy link to clipboard

Copied

LATEST

Does this help?

// tif compression check by philip cord;

// 2015, use it at your own risk;

#target photoshop

var files = selectTiffFile(true);

var theErrors = new Array;

for (var m = 0; m < files.length; m++) {

var thisFile = files;

if (getTifCompession(thisFile) != "none") {theErrors.push(thisFile)}

};

alert("these files are compressed\n"+theErrors.join("\n")); 

////////////////////////////////////

////// select file //////

function selectTiffFile (multi) {

if (multi == true) {var theString = "please select tiff files"}

else {var theString = "please select one file"};

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog (theString, '*.tif;*.tiff', multi)}

else {var theFiles = File.openDialog (theString, getFiles, multi)};

////// filter files  for mac //////

function getFiles (theFile) {

    if (theFile.name.match(/\.(tif|tiff)$/i) || theFile.constructor.name == "Folder") {

        return true

        };

  };

return theFiles

};

// by philip cord;

function getTifCompession(file){ 

if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript'); 

var xmpf = new XMPFile(file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ); 

var xmp = xmpf.getXMP(); 

try{ 

var comp = xmp.getProperty( XMPConst.NS_TIFF, "Compression" ).toString(); 

var result = ''; 

switch( Number(comp) ){   

     case 1:  result = "none"; break;   

     case 5:  result = "lzw";  break; 

     case 7:  result = "jpg";  break; 

     case 8:  result =  "zip";  break; 

     default: result =  "unknown";   

}  

return result; 

}catch(e){return undefined;} 

}; 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines