set resolution of a tiff
authortridge <>
Tue, 28 Dec 2004 23:47:54 +0000 (23:47 +0000)
committertridge <>
Tue, 28 Dec 2004 23:47:54 +0000 (23:47 +0000)
tiffsetres.c [new file with mode: 0644]

diff --git a/tiffsetres.c b/tiffsetres.c
new file mode 100644 (file)
index 0000000..6f396e8
--- /dev/null
@@ -0,0 +1,41 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "tiffio.h"
+       
+int main(int argc, char* argv[])
+{
+       TIFF *tiff;
+       double res = 17.74;
+       int i;
+       
+       if (argc < 2)
+               return 1;
+
+       res = atof(argv[1]);
+
+       res = 1.0 / (res * 1.0e-4);
+
+       for (i=2;i<argc;i++) {
+               tiff = TIFFOpen(argv[i], "r+");
+               if (tiff == NULL) {
+                       perror(argv[i]);
+                       return 2;
+               }
+       
+               /* For list of available tags and tag values see tiff.h */
+               if (TIFFSetField(tiff, TIFFTAG_RESOLUTIONUNIT, RESUNIT_CENTIMETER) != 1)
+                       fprintf( stderr, "Failed to set ResolutionUnit.\n");
+
+               /* Don't forget to calculate and set new resolution values */
+               if (TIFFSetField(tiff, TIFFTAG_XRESOLUTION, res) != 1)
+                       fprintf( stderr, "Failed to set XResolution.\n");
+               if (TIFFSetField(tiff, TIFFTAG_YRESOLUTION, res) != 1)
+                       fprintf( stderr, "Failed to set YResolution.\n");
+               
+               TIFFRewriteDirectory(tiff);
+               TIFFClose(tiff);
+       }
+
+       return 0;
+}
+