Generate a webp cover image from a CNCF project icon by flattening transparency onto a white background, scaling to match the reference logo area, and centering on a canvas sized to a reference image.
1) Collect inputs: icon URL or local file, reference image path, output path. 2) Run the script to build a centered webp with matching size. 3) Verify output size and alpha channel.
Requirements:
python3 -m pip install pillow)cwebp (preferred webp encoder)Example:
1
2
3
4
python3 scripts/generate_cncf_icon_webp.py \
--icon-url https://raw.githubusercontent.com/cncf/artwork/main/projects/istio/icon/color/istio-icon-color.png \
--reference assets/img/kubernetes/kubernetes.webp \
--output assets/img/kubernetes/istio/istio.webp
Common options:
--icon-path to use a local icon file--bbox-threshold to adjust non-white detection (default: 250)--fallback-scale when reference has no non-white pixels (default: 0.7)--background to change the canvas color (default: #ffffff)--no-cwebp to force Pillow for encodingOptional checks:
1
2
sips -g pixelWidth -g pixelHeight assets/img/kubernetes/istio/istio.webp
webpinfo -summary assets/img/kubernetes/istio/istio.webp
sips -s format png reference.webp --out /tmp/reference.png).cwebp if available for consistent encoding output.