Skip to content

Commit 3005834

Browse files
committed
Allow customizing thumbnail size
1 parent c6f9337 commit 3005834

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

comiclib/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class Settings(BaseSettings):
1111
content: str = '.'
1212
cover: str = './thumb'
1313
thumb: Union[str, None] = None
14+
thumb_width: int = 250
15+
thumb_height: int = 350
1416
metadata: str = 'sqlite:///./comiclib_metadata.db'
1517
password: Union[str, None] = None
1618
skip_exits: bool = True

comiclib/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ def convert_image(f_or_path, saveto: str, thumbnail=False):
4444
try:
4545
with Image.open(f_or_path) as im:
4646
if thumbnail:
47-
im.thumbnail((500, 709))
47+
im.thumbnail((settings.thumb_width, settings.thumb_height))
4848
im.save(saveto)
4949
except PIL.UnidentifiedImageError:
5050
if not isinstance(f_or_path, Path):
5151
with tempfile.NamedTemporaryFile() as tmpf: # libjxl has problem with pipe yet
5252
f_or_path.seek(0)
5353
shutil.copyfileobj(f_or_path, tmpf)
5454
tmpf.flush()
55-
cmd = ['ffmpeg', '-i', tmpf.name, '-vf', 'scale=500:-1', str(saveto), '-y'] if thumbnail else ['ffmpeg', '-i', tmpf.name, str(saveto), '-y']
55+
cmd = ['ffmpeg', '-i', tmpf.name, '-vf', f"scale='min({settings.thumb_width},iw)':'min({settings.thumb_height},ih)':force_original_aspect_ratio=decrease", str(saveto), '-y'] if thumbnail else ['ffmpeg', '-i', tmpf.name, str(saveto), '-y']
5656
subprocess.run(cmd, check=True, stderr=None if settings.debug else subprocess.DEVNULL)
5757
else:
58-
cmd = ['ffmpeg', '-i', str(f_or_path), '-vf', 'scale=500:-1', str(saveto), '-y'] if thumbnail else ['ffmpeg', '-i', str(f_or_path), str(saveto), '-y']
58+
cmd = ['ffmpeg', '-i', str(f_or_path), '-vf', f"scale='min({settings.thumb_width},iw)':'min({settings.thumb_height},ih)':force_original_aspect_ratio=decrease", str(saveto), '-y'] if thumbnail else ['ffmpeg', '-i', str(f_or_path), str(saveto), '-y']
5959
subprocess.run(cmd, check=True, stderr=None if settings.debug else subprocess.DEVNULL)
6060

6161

docs/en/docs/settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ The following is a list of available settings:
3131
| `content` | The path where the comic file is stored | `.` |
3232
| `cover` | The path where the generated cover thumbnails are stored | `./thumb`|
3333
| `thumb` | The path where the generated page thumbnails are stored. If not provided (`None`), will be the same as `cover`. | `None`|
34+
| `thumb_width` | Maximum thumbnail width | 250 |
35+
| `thumb_height` | Maximum thumbnail height | 350 |
3436
| `metadata` | The URL for metadata database, refer to [SQLAlchemy documentation](https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls) | `sqlite:///./comiclib_metadata.db` |
3537
| `password` | Admin password (also used as API Key currently) [^1]. If it is `None`, any visitor will have editing permissions. This feature is designed to protect against gentlemen but not villains. If you need security protection, please use e.g. the HTTP basic authentication of the reverse proxy, Cloudflare Access or TLS client certificate, etc. | `None`|
3638
| `skip_exists`| Skip comics that have been scanned into the metadata database during scanning? (`True`/`False`) | `True` |

docs/zh/docs/settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
| `content` | 漫画文件存放的路径 | `.` |
3232
| `cover` | 生成的封面缩略图存放的路径。 | `./thumb`|
3333
| `thumb` | 生成的页面缩略图存放的路径。如果未提供 (`None`),会和 `cover` 的值一样。| `None`|
34+
| `thumb_width` | 缩略图的最大宽度 | 250 |
35+
| `thumb_height` | 缩略图的最大高度 | 350 |
3436
| `metadata` | 元数据库 URL,参考[SQLAlchemy 文档](https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls) | `sqlite:///./comiclib_metadata.db` |
3537
| `password` | 管理密码(目前也用作 API 密钥)[^1],若为`None`则任何访客皆可编辑。此功能防君子不防小人,若需安全保护请借助反向代理的 HTTP 基本验证、Cloudflare Access 或 TLS 客户端证书等。| `None`|
3638
| `skip_exists`| 扫描时是否跳过曾扫入元数据库的漫画?(`True`/`False`| `True` |

0 commit comments

Comments
 (0)