// This macro displays contents of the Image Description tag
// in the header of TIFF files created by programs such ImageJ
// and MetaMorph.
//
// With ImageJ 1.39t and later this macro can be replaced by
// the built in getInfo("image.description") function.

// Author: Gilles Carpentier, Faculte des Sciences et 
// Technologies,  Universite Paris 12 Val de Marne 

  macro "Display TIFF Info" {
      if (getVersion>="1.39t") {
          print("\nImage description from '"+getTitle+"':");
          print(getInfo("image.description"));
          return;
      }
      setBatchMode(true);
      id = getImageID();
      title = getTitle();
      if (indexOf(toLowerCase(title), ".tif")==-1)
          exit("The macro requires a TIFF image");
      dir  = getDirectory("image");
      if (isOpen("Log")) {
          selectWindow("Log");
          run("Close");
      }
      setOption("DebugMode", true);
      open(dir+title);
      close();
      run("Misc...", "divide=Infinity antialiased");
      selectWindow("Log");
      info = getInfo();
      run("Close");
      setOption("DebugMode", false);
      index1 = indexOf(info, "Image Description:");
      if (index1==-1)
          exit("This TIFF does not appear to have an image description tag");
      index1 += 19;
      index2=indexOf(info, "\n", index1);
      data = substring(info, index1,index2);
      if (lengthOf(data)>200 && indexOf(data, "\n")==-1)
          exit("The image description is longer than 200 characters.");
      showMessage ("Image description from "+title, data);
}
