|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | 8 | # %% auto 0 |
9 | | -__all__ = ['spark_chars', 'UNSET', 'walk', 'globtastic', 'maybe_open', 'mkdir', 'image_size', 'bunzip', 'loads', 'loads_multi', |
10 | | - 'dumps', 'untar_dir', 'repo_details', 'shell', 'ssh', 'rsync_multi', 'run', 'open_file', 'save_pickle', |
11 | | - 'load_pickle', 'parse_env', 'expand_wildcards', 'dict2obj', 'obj2dict', 'repr_dict', 'is_listy', 'mapped', |
12 | | - 'IterLen', 'ReindexCollection', 'SaveReturn', 'trim_wraps', 'save_iter', 'asave_iter', 'friendly_name', |
13 | | - 'n_friendly_names', 'exec_eval', 'get_source_link', 'truncstr', 'sparkline', 'modify_exception', |
14 | | - 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart', 'EventTimer', 'stringfmt_names', |
15 | | - 'PartialFormatter', 'partial_format', 'utc2local', 'local2utc', 'trace', 'modified_env', 'ContextManagers', |
16 | | - 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', 'Unset', 'nullable_dc', 'make_nullable', |
17 | | - 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', 'CachedIter', 'CachedAwaitable', |
18 | | - 'reawaitable', 'flexicache', 'time_policy', 'mtime_policy', 'timed_cache'] |
| 9 | +__all__ = ['spark_chars', 'UNSET', 'walk', 'globtastic', 'maybe_open', 'mkdir', 'image_size', 'img_bytes', 'bunzip', 'loads', |
| 10 | + 'loads_multi', 'dumps', 'untar_dir', 'repo_details', 'shell', 'ssh', 'rsync_multi', 'run', 'open_file', |
| 11 | + 'save_pickle', 'load_pickle', 'parse_env', 'expand_wildcards', 'dict2obj', 'obj2dict', 'repr_dict', |
| 12 | + 'is_listy', 'mapped', 'IterLen', 'ReindexCollection', 'SaveReturn', 'trim_wraps', 'save_iter', 'asave_iter', |
| 13 | + 'friendly_name', 'n_friendly_names', 'exec_eval', 'get_source_link', 'truncstr', 'sparkline', |
| 14 | + 'modify_exception', 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart', 'EventTimer', |
| 15 | + 'stringfmt_names', 'PartialFormatter', 'partial_format', 'utc2local', 'local2utc', 'trace', 'modified_env', |
| 16 | + 'ContextManagers', 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', 'Unset', 'nullable_dc', |
| 17 | + 'make_nullable', 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', 'CachedIter', |
| 18 | + 'CachedAwaitable', 'reawaitable', 'flexicache', 'time_policy', 'mtime_policy', 'timed_cache'] |
19 | 19 |
|
20 | 20 | # %% ../nbs/03_xtras.ipynb |
21 | 21 | from .imports import * |
@@ -126,6 +126,14 @@ def _png_size(f): |
126 | 126 | d = dict(png=_png_size, gif=_gif_size, jpeg=_jpg_size) |
127 | 127 | with maybe_open(fn, 'rb') as f: return d[imghdr.what(f)](f) |
128 | 128 |
|
| 129 | +# %% ../nbs/03_xtras.ipynb |
| 130 | +def img_bytes(img, fmt='PNG'): |
| 131 | + # Convert PIL `img` to bytes in format `fmt` |
| 132 | + from io import BytesIO |
| 133 | + buf=BytesIO() |
| 134 | + img.save(buf, format=fmt) |
| 135 | + return buf.getvalue() |
| 136 | + |
129 | 137 | # %% ../nbs/03_xtras.ipynb |
130 | 138 | def bunzip(fn): |
131 | 139 | "bunzip `fn`, raising exception if output already exists" |
|
0 commit comments