@@ -68,15 +68,15 @@ def optimize_png(
68
68
Arguments:
69
69
reduce_colors: Whether to reduce colors using adaptive color pallette (boolean)
70
70
values: True | False
71
- max_colors: Maximum number of colors
72
- if reduce_colors is True (integer between 1 and 256)
71
+ max_colors: Maximum number of colors if reduce_colors is True (integer between
72
+ 1 and 256)
73
73
values: 35 | 64 | 256 | 128 | XX
74
74
fast_mode: Whether to use faster but weaker compression (boolean)
75
75
values: True | False
76
76
remove_transparency: Whether to remove transparency (boolean)
77
77
values: True | False
78
- background_color: Background color
79
- if remove_transparency is True (tuple containing RGB values)
78
+ background_color: Background color if remove_transparency is True (tuple
79
+ containing RGB values)
80
80
values: (255, 255, 255) | (221, 121, 108) | (XX, YY, ZZ)"""
81
81
82
82
ensure_matches (src , "PNG" )
@@ -110,13 +110,15 @@ def optimize_jpeg(
110
110
** _ ,
111
111
) -> pathlib .Path | io .BytesIO :
112
112
"""method to optimize JPEG files using a pure python external optimizer
113
- quality: JPEG quality (integer between 1 and 100)
114
- values: 50 | 55 | 35 | 100 | XX
115
- keep_exif: Whether to keep EXIF data in JPEG (boolean)
116
- values: True | False
117
- fast_mode: Use the supplied quality value. If turned off, optimizer will
118
- get dynamic quality value to ensure better compression
119
- values: True | False"""
113
+
114
+ Arguments:
115
+ quality: JPEG quality (integer between 1 and 100)
116
+ values: 50 | 55 | 35 | 100 | XX
117
+ keep_exif: Whether to keep EXIF data in JPEG (boolean)
118
+ values: True | False
119
+ fast_mode: Use the supplied quality value. If turned off, optimizer will
120
+ get dynamic quality value to ensure better compression
121
+ values: True | False"""
120
122
121
123
ensure_matches (src , "JPEG" )
122
124
@@ -179,14 +181,16 @@ def optimize_webp(
179
181
** _ ,
180
182
) -> pathlib .Path | io .BytesIO :
181
183
"""method to optimize WebP using Pillow options
182
- lossless: Whether to use lossless compression (boolean)
183
- values: True | False
184
- quality: WebP quality for lossy, effort put into compression
185
- for lossless (integer between 0 to 100)
186
- values: 30 | 45 | 100 | XX
187
- method: Quality/speed trade-off;
188
- higher values give better compression (integer between 1 and 6)
189
- values: 1 | 2 | 3 | 4 | 5 | 6
184
+
185
+ Arguments:
186
+ lossless: Whether to use lossless compression (boolean);
187
+ values: True | False
188
+ quality: WebP quality for lossy, effort put into compression for lossless
189
+ (integer between 0 to 100);
190
+ values: 30 | 45 | 100 | XX
191
+ method: Quality/speed trade-off; higher values give better compression (integer
192
+ between 1 and 6);
193
+ values: 1 | 2 | 3 | 4 | 5 | 6
190
194
191
195
refer to the link for more details
192
196
https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#webp"""
@@ -230,18 +234,21 @@ def optimize_gif(
230
234
** _ ,
231
235
) -> pathlib .Path :
232
236
"""method to optimize GIFs using gifsicle >= 1.92
233
- optimize_level: Optimization level;
234
- higher values give better compression (integer between 1 and 3)
235
- values: 1 | 2 | 3
236
- lossiness: Level of lossy optimization to use;
237
- higher values give better compression (integer)
238
- values: 20 | 45 | 80 | XX
239
- interlace: Whether to interlace the frames (boolean)
240
- values: True | False
241
- no_extensions: Whether to remove all extension options from GIF (boolean)
242
- values: True | False
243
- max_colors: Maximum number of colors in resultant GIF (integer between 2 and 256)
244
- values: 2 | 86 | 128 | 256 | XX
237
+
238
+ Arguments:
239
+ optimize_level: Optimization level; higher values give better compression
240
+ (integer between 1 and 3);
241
+ values: 1 | 2 | 3
242
+ lossiness: Level of lossy optimization to use; higher values give better
243
+ compression (integer)
244
+ values: 20 | 45 | 80 | XX
245
+ interlace: Whether to interlace the frames (boolean)
246
+ values: True | False
247
+ no_extensions: Whether to remove all extension options from GIF (boolean)
248
+ values: True | False
249
+ max_colors: Maximum number of colors in resultant GIF;
250
+ (integer between 2 and 256)
251
+ values: 2 | 86 | 128 | 256 | XX
245
252
246
253
refer to the link for more details - https://www.lcdf.org/gifsicle/man.html"""
247
254
@@ -282,12 +289,13 @@ def optimize_image(
282
289
):
283
290
"""Optimize image, automatically selecting correct optimizer
284
291
285
- delete_src: whether to remove src file upon success (boolean)
286
- values: True | False
287
- convert: whether/how to convert from source before optimizing (str or boolean)
288
- values: False: don't convert
289
- True: convert to format implied by dst suffix
290
- "FMT": convert to format FMT (use Pillow names)"""
292
+ Arguments:
293
+ delete_src: whether to remove src file upon success (boolean)
294
+ values: True | False
295
+ convert: whether/how to convert from source before optimizing (str or boolean)
296
+ values: False: don't convert
297
+ True: convert to format implied by dst suffix
298
+ "FMT": convert to format FMT (use Pillow names)"""
291
299
292
300
src_format , dst_format = format_for (src , from_suffix = False ), format_for (dst )
293
301
0 commit comments