28
28
import os
29
29
import pathlib
30
30
import subprocess
31
- from typing import Optional , Union
32
31
33
32
import piexif
34
33
from optimize_images .img_aux_processing import do_reduce_colors , rebuild_palette
@@ -52,15 +51,15 @@ def ensure_matches(
52
51
53
52
54
53
def optimize_png (
55
- src : Union [ pathlib .Path , io .BytesIO ] ,
56
- dst : Optional [ pathlib .Path ] = None ,
57
- reduce_colors : Optional [ bool ] = False , # noqa: FBT002
58
- max_colors : Optional [ int ] = 256 ,
59
- fast_mode : Optional [ bool ] = True , # noqa: FBT002
60
- remove_transparency : Optional [ bool ] = False , # noqa: FBT002
61
- background_color : Optional [ tuple [int , int , int ]] = (255 , 255 , 255 ),
54
+ src : pathlib .Path | io .BytesIO ,
55
+ dst : pathlib .Path | None = None ,
56
+ reduce_colors : bool | None = False , # noqa: FBT002
57
+ max_colors : int | None = 256 ,
58
+ fast_mode : bool | None = True , # noqa: FBT002
59
+ remove_transparency : bool | None = False , # noqa: FBT002
60
+ background_color : tuple [int , int , int ] | None = (255 , 255 , 255 ),
62
61
** options , # noqa: ARG001
63
- ) -> Union [ pathlib .Path , io .BytesIO ] :
62
+ ) -> pathlib .Path | io .BytesIO :
64
63
"""method to optimize PNG files using a pure python external optimizer
65
64
66
65
Arguments:
@@ -99,13 +98,13 @@ def optimize_png(
99
98
100
99
101
100
def optimize_jpeg (
102
- src : Union [ pathlib .Path , io .BytesIO ] ,
103
- dst : Optional [ pathlib .Path ] = None ,
104
- quality : Optional [ int ] = 85 ,
105
- fast_mode : Optional [ bool ] = True , # noqa: FBT002
106
- keep_exif : Optional [ bool ] = True , # noqa: FBT002
101
+ src : pathlib .Path | io .BytesIO ,
102
+ dst : pathlib .Path | None = None ,
103
+ quality : int | None = 85 ,
104
+ fast_mode : bool | None = True , # noqa: FBT002
105
+ keep_exif : bool | None = True , # noqa: FBT002
107
106
** options , # noqa: ARG001
108
- ) -> Union [ pathlib .Path , io .BytesIO ] :
107
+ ) -> pathlib .Path | io .BytesIO :
109
108
"""method to optimize JPEG files using a pure python external optimizer
110
109
quality: JPEG quality (integer between 1 and 100)
111
110
values: 50 | 55 | 35 | 100 | XX
@@ -169,13 +168,13 @@ def optimize_jpeg(
169
168
170
169
171
170
def optimize_webp (
172
- src : Union [ pathlib .Path , io .BytesIO ] ,
173
- dst : Optional [ pathlib .Path ] = None ,
174
- lossless : Optional [ bool ] = False , # noqa: FBT002
175
- quality : Optional [ int ] = 60 ,
176
- method : Optional [ int ] = 6 ,
171
+ src : pathlib .Path | io .BytesIO ,
172
+ dst : pathlib .Path | None = None ,
173
+ lossless : bool | None = False , # noqa: FBT002
174
+ quality : int | None = 60 ,
175
+ method : int | None = 6 ,
177
176
** options , # noqa: ARG001
178
- ) -> Union [ pathlib .Path , io .BytesIO ] :
177
+ ) -> pathlib .Path | io .BytesIO :
179
178
"""method to optimize WebP using Pillow options
180
179
lossless: Whether to use lossless compression (boolean)
181
180
values: True | False
@@ -214,11 +213,11 @@ def optimize_webp(
214
213
def optimize_gif (
215
214
src : pathlib .Path ,
216
215
dst : pathlib .Path ,
217
- optimize_level : Optional [ int ] = 1 ,
218
- lossiness : Optional [ int ] = None ,
219
- interlace : Optional [ bool ] = True , # noqa: FBT002
220
- no_extensions : Optional [ bool ] = True , # noqa: FBT002
221
- max_colors : Optional [ int ] = None ,
216
+ optimize_level : int | None = 1 ,
217
+ lossiness : int | None = None ,
218
+ interlace : bool | None = True , # noqa: FBT002
219
+ no_extensions : bool | None = True , # noqa: FBT002
220
+ max_colors : int | None = None ,
222
221
** options , # noqa: ARG001
223
222
) -> pathlib .Path :
224
223
"""method to optimize GIFs using gifsicle >= 1.92
@@ -267,8 +266,8 @@ def optimize_gif(
267
266
def optimize_image (
268
267
src : pathlib .Path ,
269
268
dst : pathlib .Path ,
270
- delete_src : Optional [ bool ] = False , # noqa: FBT002
271
- convert : Optional [ Union [ bool , str ]] = False , # noqa: FBT002
269
+ delete_src : bool | None = False , # noqa: FBT002
270
+ convert : bool | str | None = False , # noqa: FBT002
272
271
** options ,
273
272
) -> bool : # pyright: ignore
274
273
"""Optimize image, automatically selecting correct optimizer
0 commit comments