zimscraperlib.image
Modules:
-
conversion– -
illustration– -
optimization–An image optimization module to optimize the following image formats:
-
presets– -
probing– -
transformation– -
utils–
Functions:
-
convert_image–convert an image file from one format to another
-
is_valid_image–whether image is a valid imformat (PNG) image, optionnaly of requested size
-
optimize_image–Optimize image, automatically selecting correct optimizer
-
resize_image–resize an image to requested dimensions
convert_image
convert an image file from one format to another params: Image.save() parameters. Depends on dest format. params can include the following keys: - fmt: specify the dest format (otherwise guessed from extension) ex: JPEG, PNG, BMP (and other PIL formats) - colorspace: convert to this colorspace. Otherwise not converted unless target format has no halpha channel while source had. In this case converted to RGB. ex: RGB, ARGB, CMYK (and other PIL colorspaces)
Source code in src/zimscraperlib/image/conversion.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
is_valid_image
is_valid_image(
image: Path | bytes | BytesIO,
imformat: str,
size: tuple[int, int] | None = None,
) -> bool
whether image is a valid imformat (PNG) image, optionnaly of requested size
Source code in src/zimscraperlib/image/probing.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
optimize_image
optimize_image(
src: Path | BytesIO | bytes,
dst: Path | BytesIO,
options: OptimizeOptions | None = None,
*,
dst_format: str | None = None,
delete_src: bool = False,
convert: bool | str = False,
) -> Path | BytesIO
Optimize image, automatically selecting correct optimizer
Parameters:
-
dst_format(str | None, default:None) –format of the destination image, required when dst is io.BytesIO.
-
delete_src(bool, default:False) –whether to remove src file upon success (boolean) values: True | False
-
convert(bool | str, default:False) –will be deprecated in scraperlib 6, use dst_format instead. values: False: don't convert True: convert to format implied by dst suffix str: convert to the specified format
Source code in src/zimscraperlib/image/optimization.py
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
resize_image
resize_image(
src: Path | BytesIO,
width: int,
height: int | None = None,
dst: Path | BytesIO | None = None,
method: str | None = "width",
*,
allow_upscaling: bool | None = True,
**params: str,
) -> None
resize an image to requested dimensions
methods: width, height, cover, thumbnail allow upscaling: upscale image first, preserving aspect ratio if required
Source code in src/zimscraperlib/image/transformation.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | |