Reference

A package to convert a list or folder of images into a contact sheet style PDF.

imagecatalog.create_catalog(fname, images, labels=None, notes=None, orientation='portrait', rows=4, cols=3, autocontrast=False, grayscale=False, invert=False)

Convenience method to generate an image catalog and save as PDF.

Parameters
  • fname (Union[str, bytes, Path]) – pdf output filename

  • images (List[Union[str, bytes, Path, Image]]) – list of images

  • labels (Optional[List[str]]) – list of labels for images, should be same length as images, displayed above image. If None, labels will be file names (if available). Defaults to None.

  • notes (Optional[List[str]]) – list of notes for images, should be same length as images, displayed below image. Defaults to None.

  • rows (int) – number of rows per page

  • cols (int) – number of columns per page

  • orientation (str) – page orientation, possible values are “portrait” and “landscape”. Defaults to “portrait”.

  • autocontrast (bool) – apply autocontrast adjustment. Defaults to False.

  • grayscale (bool) – convert color image to grayscale. Defaults to False.

  • invert (bool) – invert image colors. Defaults to False.

Todo

  • return filename

  • check that file was written else raise error

class imagecatalog.Catalog(orientation='portrait', unit='mm', format='A4', **kwargs)

A class to create contact sheets from images, labels, and notes.

Example

>>> # generate sample data
>>> from PIL import Image
>>> images = [Image.new("RGB", (200, 200), "gray") for _ in range(9)]
>>> labels = [f"Image {i}" for i in range(9)]
>>> notes = [f"image {i} note" for i in range(9)]
>>> from imagecatalog import Catalog
>>> catalog = Catalog()
>>> # optionally add a title
>>> catalog.set_title("Image Catalog")
>>> catalog.add_page()
>>> catalog.build_table(images, labels, notes, rows=4, cols=3)
>>> catalog.output("catalog.pdf")
__init__(orientation='portrait', unit='mm', format='A4', **kwargs)

Instantiate an FPDF object.

Parameters
  • orientation (str) – page orientation, possible values are “portrait” and “landscape”. Defaults to “portrait”.

  • unit (str) – possible values are “pt”, “mm”, “cm”, “in”, or a number

  • format (str) – possible values are “a3”, “a4”, “a5”, “letter”, “legal” or a tuple (width, height) expressed in the given unit. Defaults to “a4”.

  • **kwargs – keyword arguments passed to fpdf.FPDF

build_table(images, labels=None, notes=None, rows=4, cols=3, autocontrast=False, grayscale=False, invert=False)

Insert the catalog table into the pdf.

Parameters
  • images (List[Union[str, bytes, Path, Image]]) – list of images

  • labels (Optional[List[str]]) – list of labels for images, should be same length as images, displayed above image. If None, labels will be file names (if available). Defaults to None.

  • notes (Optional[List[str]]) – list of notes for images, should be same length as images, displayed below image. Defaults to None.

  • rows (int) – number of rows per page. Defaults to 4.

  • cols (int) – number of columns per page. Defaults to 3.

  • autocontrast (bool) – apply autocontrast adjustment. Defaults to False.

  • grayscale (bool) – convert color image to grayscale. Defaults to False.

  • invert (bool) – invert image colors. Defaults to False.

Raises

ValueErrorimages and labels (if supplied) and notes (if supplied) are not equal lengths.