Skip to content

Instantly share code, notes, and snippets.

@jcupitt
Created December 10, 2022 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jcupitt/912b0da1c95b615152fa0fbd6e4cc821 to your computer and use it in GitHub Desktop.
Save jcupitt/912b0da1c95b615152fa0fbd6e4cc821 to your computer and use it in GitHub Desktop.
make a multipage tiff file
/* compile with
*
* gcc -Wall createtiff.c `pkg-config libtiff --cflags --libs`
*/
#include <tiffio.h>
int
main (int argc, const char **argv)
{
TIFF *tiff;
if (!(tiff = TIFFOpen(argv[1], "w")))
return 1;
for (int i = 0; i < 10; i++) {
char pixel[1] = { 128 };
TIFFSetField (tiff, TIFFTAG_IMAGEWIDTH, 1);
TIFFSetField (tiff, TIFFTAG_IMAGELENGTH, 1);
TIFFSetField (tiff, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField (tiff, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField (tiff, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
if (TIFFWriteScanline(tiff, pixel, 0, 0) < 0)
return 1;
if (!TIFFWriteDirectory(tiff))
return 1;
}
TIFFClose (tiff);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment