imgutils.metadata.geninfo

This module provides functions for reading and writing generation information (geninfo) to image files. It supports different image formats including PNG, EXIF, and GIF.

The module includes functions for:

  1. Reading geninfo from image parameters, EXIF data, and GIF comments

  2. Writing geninfo to image parameters, EXIF data, and GIF comments

These functions are useful for storing and retrieving metadata about image generation, particularly in the context of AI-generated images.

read_geninfo_parameters

imgutils.metadata.geninfo.read_geninfo_parameters(image: str | PathLike | bytes | bytearray | BinaryIO | Image) str | None[source]

Read generation information from image parameters.

Parameters:

image (ImageTyping) – The input image.

Returns:

The generation information if found, None otherwise.

Return type:

Optional[str]

This function loads the image and attempts to retrieve the ‘parameters’ information from the image metadata. It’s commonly used for PNG images where generation information is stored in the image parameters.

read_geninfo_exif

imgutils.metadata.geninfo.read_geninfo_exif(image: str | PathLike | bytes | bytearray | BinaryIO | Image) str | None[source]

Read generation information from EXIF data.

Parameters:

image (ImageTyping) – The input image.

Returns:

The generation information if found in EXIF data, None otherwise.

Return type:

Optional[str]

This function attempts to read generation information from the EXIF metadata of the image. It specifically looks for the UserComment field in the EXIF data. If the EXIF data is invalid or not present, it returns None.

read_geninfo_gif

imgutils.metadata.geninfo.read_geninfo_gif(image: str | PathLike | bytes | bytearray | BinaryIO | Image) str | None[source]

Read generation information from GIF comment.

Parameters:

image (ImageTyping) – The input image.

Returns:

The generation information if found in GIF comment, None otherwise.

Return type:

Optional[str]

This function is specifically designed to read generation information from GIF images. It looks for the ‘comment’ field in the image metadata, which is commonly used in GIF files to store additional information.

write_geninfo_parameters

imgutils.metadata.geninfo.write_geninfo_parameters(image: str | PathLike | bytes | bytearray | BinaryIO | Image, dst_filename: str, geninfo: str, **kwargs)[source]

Write generation information to image parameters.

Parameters:
  • image (ImageTyping) – The input image.

  • dst_filename (str) – The destination filename to save the image with geninfo.

  • geninfo (str) – The generation information to write.

  • kwargs – Additional keyword arguments to pass to the image save function.

This function writes the provided generation information to the image parameters. It’s commonly used for PNG images where generation information can be stored in the image metadata. The function creates a PngInfo object, adds the geninfo as ‘parameters’, and saves the image with this metadata.

write_geninfo_exif

imgutils.metadata.geninfo.write_geninfo_exif(image: str | PathLike | bytes | bytearray | BinaryIO | Image, dst_filename: str, geninfo: str, **kwargs)[source]

Write generation information to EXIF data.

Parameters:
  • image (ImageTyping) – The input image.

  • dst_filename (str) – The destination filename to save the image with geninfo.

  • geninfo (str) – The generation information to write.

  • kwargs – Additional keyword arguments to pass to the image save function.

This function writes the provided generation information to the EXIF metadata of the image. It creates an EXIF dictionary with the geninfo stored in the UserComment field, converts it to bytes, and saves the image with this EXIF data.

write_geninfo_gif

imgutils.metadata.geninfo.write_geninfo_gif(image: str | PathLike | bytes | bytearray | BinaryIO | Image, dst_filename: str, geninfo: str, **kwargs)[source]

Write generation information to GIF comment.

Parameters:
  • image (ImageTyping) – The input image.

  • dst_filename (str) – The destination filename to save the image with geninfo.

  • geninfo (str) – The generation information to write.

  • kwargs – Additional keyword arguments to pass to the image save function.

This function is specifically designed to write generation information to GIF images. It adds the geninfo to the image’s ‘comment’ field, which is a standard way of including metadata in GIF files.