Search code examples
tiff

Is there a standard way to add textual information in a TIFF file with FreeImage?


I have a program that generates its results as TIFF files. I would like to add some textual information in theses files to keep a trace of the program parameters.

I know that a tag named "ImageDescription" can be added in a tiff file (according to the specification file p34), if I could put the program parameters in that field, it will be ok for me.

But is it possible to set this tag with FreeImage?

If it's not possible, can I add EXIF information to my tiff file with FreeImage?


Solution

  • I answer my own question.

    With FreeImage, one simple way to add metadata is to use IPTC tags:

    void addTag(FIBITMAP *bitmap, const char *key, const char *value)
    {
        FITAG *tag = FreeImage_CreateTag();
        size_t len = strlen(value)+1;
        FreeImage_SetTagKey(tag, len);
        FreeImage_SetTagCount(tag, len);
        FreeImage_SetTagType(tag, FIDT_ASCII);
        FreeImage_SetTagValue(tag, value);
        FreeImage_SetMetadata(FIMD_IPTC, bitmap, FreeImage_GetTagKey(tag), tag);
        FreeImage_DeleteTag(tag);
    }
    

    And, use these function with valid IPTC tags:

    // set creator's name, limited to 32 bytes
    addTag(bitmap, "By-line", "Creator's name");
    // set keyword, limited to 64 bytes
    addTag(bitmap, "Keywords", "Param1=foo;Param2=bar");