Module fpdf.image_parsing
Functions
def ccitt_payload_location_from_pil(img)
-
returns the byte offset and length of the CCITT payload in the original TIFF data
def clear_table()
-
Reset the encoding table and coding state to initial conditions.
def get_img_info(filename, img=None, image_filter='AUTO', dims=None)
-
Args
filename
- in a format that can be passed to load_image
img
- optional
bytes
,BytesIO
orPIL.Image.Image
instance image_filter
:str
- one of the SUPPORTED_IMAGE_FILTERS
def get_svg_info(filename, img, image_cache)
def is_iccp_valid(iccp, filename)
-
Checks the validity of an ICC profile
def load_image(filename)
-
This method is used to load external resources, such as images. It is automatically called when resource added to document by
fpdf.FPDF.image()
. It always return a BytesIO buffer. def pack_codes_into_bytes(codes)
-
Convert the list of result codes into a continuous byte stream, with codes packed as per the code bit-width. The bit-width starts at 9 bits and expands as needed.
def preload_image(image_cache: ImageCache, name, dims=None)
-
Read an image and load it into memory.
For raster images: following this call, the image is inserted in
image_cache.images
, and following calls toFPDF.image()
will re-use the same cached values, without re-reading the image.For vector images: the data is loaded and the metadata extracted.
Args
image_cache
- an
ImageCache
instance, usually the.image_cache
attribute of aFPDF
instance. name
- either a string representing a file path to an image, an URL to an image,
an io.BytesIO, or a instance of
PIL.Image.Image
. dims
:Tuple[float]
- optional dimensions as a tuple (width, height) to resize the image (raster only) before storing it in the PDF.
Returns: A tuple, consisting of 3 values: the name, the image data, and an instance of a subclass of
ImageInfo
. def transcode_monochrome(img)
-
Convert the open PIL.Image imgdata to compressed CCITT Group4 data.
Classes
class ImageSettings (compression_level: int = -1)
-
ImageSettings(compression_level: int = -1)
Expand source code Browse git
@dataclass class ImageSettings: # Passed to zlib.compress() - In range 0-9 - Default is currently equivalent to 6: compression_level: int = -1
Class variables
var compression_level : int
class temp_attr (obj, field, value)
-
temporary change the attribute of an object using a context manager
Expand source code Browse git
class temp_attr: """ temporary change the attribute of an object using a context manager """ def __init__(self, obj, field, value): self.obj = obj self.field = field self.value = value def __enter__(self): self.exists = False if hasattr(self.obj, self.field): self.exists = True self.old_value = getattr(self.obj, self.field) setattr(self.obj, self.field, self.value) def __exit__(self, exctype, excinst, exctb): if self.exists: setattr(self.obj, self.field, self.old_value) else: delattr(self.obj, self.field)