Skip to content

A python library for trimming PDF cover artworks and outputting JPEG front covers

License

Notifications You must be signed in to change notification settings

OpenBookPublishers/cover-trimmer

Repository files navigation

cover-trimmer

cover-trimmer is a python library for trimming PDF cover artworks and outputting JPEG representations of their front covers.

Usage

from cover_trimmer import Trimmer

# init Trimmer object
trimmer = Trimmer(pdf_path, output_folder=out_folder)

# set cropbox to front cover coordinates
trimmer.set_cropbox([748, 9, 1190, 672])

# trim PDF and output a JPEG 1200 pixels wide
trimmer.convert(1200)

The front page coordinates element is a python list with the PyMuPDF Rect() set of references you require (units are expressed in points).

Thoth Wrapper (Optional)

The Thoth wrapper stored at ./src/thoth_wrapper.py queries the metadata repository to apply the correct cropbox to the PDF cover artworks.

Built the docker container with: $docker build . -t openbookpublishers/cover-trimmer

Run the container with:

docker run --rm \
    -v /path/to/cover.pdf:/cover/cover.pdf \
    -v /path/to/out/:/cover/out \
    openbookpublishers/cover-trimmer \
    thoth_wrapper.py --doi 10.11647/obp.0231 --output_width 1875

where:

  • /path/to/cover.pdf is the path of the input PDF cover artwork;
  • /path/to/out/ is the path to the output directory;

Tests

docker build . -f Dockerfile.test -t openbookpublishers/cover-trimmer:test && \
docker run openbookpublishers/cover-trimmer:test

Contributing

Pull requests are welcome.

License

GPLv3