Add logo to cover for Open Graph¶
The logo_on_cover.py file provides a Flask blueprint that dynamically generates cover images with a logo overlaid in a specified corner as an image that can be used for an Open Graph . It exposes an HTTP endpoint that takes a cover image filename and optional query parameters (logo scale, corner, margin), composites the logo onto the cover, and returns the resulting PNG image. The file also implements caching to optimize repeated requests for the same parameters.
The main responsibilities of this file are:
- Loading and converting an SVG logo to PNG.
- Overlaying the logo onto a cover image at a configurable position and scale.
- Serving the composited image via a Flask route, with input validation and caching.
🔌 API¶
logo_on_cover
¶
Functions:
| Name | Description |
|---|---|
create_og_cover_blueprint |
Creates a Flask blueprint for serving cover images with a logo overlay. |
overlay_logo_bytes |
Overlays a logo onto a cover image and returns the composited image as PNG bytes. |
create_og_cover_blueprint(path_logo, logger=None)
¶
Creates a Flask blueprint for serving cover images with a logo overlay.
This function sets up routes and logic for handling requests to overlay a logo on cover images, including caching and query parameter validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger | None
|
An optional Logger instance for logging. |
None
|
Returns:
| Type | Description |
|---|---|
Blueprint
|
A Flask Blueprint configured for cover image overlay routes. |
Source code in src/routes/logo_on_cover.py
overlay_logo_bytes(cover_bytes, svg_bytes, *, logo_scale=0.4, corner='bottom_right', margin=10)
¶
Overlays a logo onto a cover image and returns the composited image as PNG bytes.
This function places a logo, provided as SVG bytes, onto a cover image at a specified corner and scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cover_bytes
|
bytes
|
The cover image data as bytes. |
required |
svg_bytes
|
bytes
|
The SVG logo image data as bytes. |
required |
logo_scale
|
float
|
The scale of the logo relative to the shortest side of the cover image. |
0.4
|
corner
|
str
|
The corner of the cover image to place the logo ('bottom_right', 'bottom_left', 'top_right', 'top_left'). |
'bottom_right'
|
margin
|
int
|
The margin in pixels between the logo and the edge of the cover image. |
10
|
Returns:
| Type | Description |
|---|---|
bytes
|
PNG image data as bytes with the logo overlaid. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an unsupported corner is specified. |
