Skip to content

Commit

Permalink
Added docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
pietermarsman committed Mar 21, 2022
1 parent cc29480 commit b71477c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pdfminer/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(self, outdir: str) -> None:
os.makedirs(self.outdir)

def export_image(self, image: LTImage) -> str:
"""Save an LTImage to disk"""
(width, height) = image.srcsize

filters = image.stream.get_filters()
Expand Down Expand Up @@ -124,6 +125,7 @@ def export_image(self, image: LTImage) -> str:
return name

def _save_jpeg(self, image: LTImage) -> str:
"""Save a JPEG encoded image"""
raw_data = image.stream.get_rawdata()
assert raw_data is not None

Expand All @@ -146,6 +148,7 @@ def _save_jpeg(self, image: LTImage) -> str:
return name

def _save_jpeg2000(self, image: LTImage) -> str:
"""Save a JPEG 2000 encoded image"""
raw_data = image.stream.get_rawdata()
assert raw_data is not None

Expand All @@ -166,6 +169,7 @@ def _save_jpeg2000(self, image: LTImage) -> str:
return name

def _save_jbig2(self, image: LTImage) -> str:
"""Save a JBIG2 encoded image"""
name, path = self._create_unique_image_name(image, ".jb2")
with open(path, "wb") as fp:
input_stream = BytesIO()
Expand Down Expand Up @@ -197,6 +201,7 @@ def _save_bmp(
self, image: LTImage, width: int, height: int, bytes_per_line: int,
bits: int
) -> str:
"""Save a BMP encoded image"""
name, path = self._create_unique_image_name(image, ".bmp")
with open(path, "wb") as fp:
bmp = BMPWriter(fp, bits, width, height)
Expand All @@ -208,6 +213,7 @@ def _save_bmp(
return name

def _save_bytes(self, image: LTImage) -> str:
"""Save an image without encoding, just bytes"""
name, path = self._create_unique_image_name(image, ".jpg")
width, height = image.srcsize
channels = len(image.stream.get_data()) / width / height / (image.bits / 8)
Expand All @@ -233,6 +239,7 @@ def _save_bytes(self, image: LTImage) -> str:
return name

def _save_raw(self, image: LTImage) -> str:
"""Save an image with unknown encoding"""
ext = ".%d.%dx%d.img" % (image.bits, image.srcsize[0], image.srcsize[1])
name, path = self._create_unique_image_name(image, ext)

Expand Down

0 comments on commit b71477c

Please sign in to comment.