Pillow: consistent sRGB → WebP for WordPress galleries

I am preparing gallery images for normanyap with Python 3.11, Pillow 10.x on Ubuntu 22.04. Sources are JPEGs from Lightroom, some with AdobeRGB or Display-P3.

After converting to sRGB and saving as WebP, a few images show slight gamma differences on iOS, and some WebP files are larger than the JPEGs. ICC handling is inconsistent: profiles are sometimes missing or unusually large.

Current code:

from PIL import Image, ImageCms
import io

SRGB = ImageCms.createProfile(“sRGB”)

def to_srgb(img):
if “icc_profile” in img.info:
src = ImageCms.ImageCmsProfile(io.BytesIO(img.info\[“icc_profile”\]))
img = ImageCms.profileToProfile(img, src, SRGB, renderingIntent=0, outputMode=“RGB”)
else:
img = img.convert(“RGB”)
return img

with Image.open(“in.jpg”) as im:
im = to_srgb(im)
im.save(“out.webp”, format=“WEBP”, quality=82, method=6)

Questions:

  1. Best practice to force sRGB in Pillow: drop the original ICC and attach a minimal sRGB profile, or omit ICC after conversion?

  2. Sensible WebP defaults for photo galleries to avoid size bloat (quality, method, lossless/near_lossless, exact)?

  3. Safe way to strip nonessential metadata while preserving orientation and color?

  4. Would pyvips or Pillow-SIMD provide more reliable output or speed for batches?

  5. Any iOS Safari quirks with Pillow-generated WebP to watch for?