Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ These tests are dependent on `pytest-docker`, and use the [./tests/docker-compos

OpenAPI docs for the appetiser API can be found at [http://localhost:8000/docs](http://localhost:8000/docs) on a locally running instance of appetiser. These provide documentation and examples for the `convert/` endpoint, along with expected types.

## Customising

The following environment variables can be used to configure the service

| EnvVar | Description | Default |
| -------------- | ----------------------------------------------- | ------- |
| `JPEG_QUALITY` | Integer, 0-100, controls thumbnail jpeg quality | 90 |
2 changes: 2 additions & 0 deletions appetiser/convert/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from pydantic import conint
from pydantic_settings import BaseSettings, SettingsConfigDict
from pathlib import Path

Expand All @@ -7,4 +8,5 @@ class ConvertConfig(BaseSettings):
KDU_EXPAND: Path
KDU_LIB: Path
OUTPUT_DIR: Path
JPEG_QUALITY: conint(ge=0, le=100) = 90
model_config = SettingsConfigDict(case_sensitive=True)
7 changes: 4 additions & 3 deletions appetiser/convert/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
)
from PIL.Image import Image as PILImage

from .config import ConvertConfig
from .kdu import IMAGE_MODES

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -278,7 +279,7 @@ def scale_dimensions_to_fit(


def resize_and_save_img(
img: PILImage, width: int, height: int, dest_path: Path
img: PILImage, width: int, height: int, dest_path: Path, config: ConvertConfig
) -> PILImage:
"""Resize a PIL Image so that it fits within a square of the provided size,
and saves this file to the provided dest_path.
Expand All @@ -287,6 +288,6 @@ def resize_and_save_img(
"""
img = img.resize((width, height), resample=Image.LANCZOS)
logger.debug(f"Image resized: {width=}, {height=})")
img.save(dest_path, quality=90)
logger.debug(f"Resized image saved to: {dest_path}")
img.save(dest_path, quality=config.JPEG_QUALITY)
logger.debug(f"Resized image saved to: {dest_path}. Quality: {config.JPEG_QUALITY}")
return img
1 change: 1 addition & 0 deletions appetiser/convert/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def create_thumbnails(
width=calc_thumb_info.width,
height=calc_thumb_info.height,
dest_path=calc_thumb_info.path,
config=config
)
thumbnail_info.append(
ThumbInfo(
Expand Down
2 changes: 2 additions & 0 deletions appetiser/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
def get_convert_config():
return ConvertConfig()

# call to validate config is correct
get_convert_config()

@app.get("/ping")
def ping():
Expand Down
Loading