rasterize
estimate_png_byte_size(image, assummed_compression_ratio=4.0, overhead_bytes=1024)
Provides an estimate of the size of a PNG image given the uncompressed size and an assumed compression ratio.
The default compression ratio of 4.0 is based on the assumption that the image is a document, and represents a pessimistic estimate.
Source code in docprompt/rasterize.py
mask_image_from_bboxes(image, bboxes, *, mask_color='black')
Given a set of normalized bounding boxes, masks the image. :param image: PIL Image object or bytes object representing an image. :param bboxes: Iterable of NormBBox objects. :param mask_color: Color used for the mask, can be a string (e.g., "black") or a tuple (e.g., (0, 0, 0)).
Source code in docprompt/rasterize.py
resize_image_to_fize_size_limit(image, max_file_size_bytes, *, resize_mode='thumbnail', resize_step_size=0.1, allow_channel_reduction=True, image_convert_mode='L')
Incrementally resizes an image until it is under a certain file size