技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
formats-and-metadata【数据与研究】Use this Pillow sub-skill when an agent needs to open or save specific image formats, choose encoder options, preserve metadata, handle animated or multi-page images, or diagnose optional codec support.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill for format I/O decisions: detecting input formats, selecting save formats and encoder options, preserving metadata, iterating multi-frame images, and checking whether the installed Pillow build has optional libraries such as JPEG, JPEG 2000, zlib, libtiff, WebP, AVIF, and LittleCMS.
Image.open(fp, mode="r", formats=None); do not trust filename extensions for input identification.format="PNG", format="JPEG", etc. for file-like objects or extensionless paths.features.check("webp"), features.check("avif"), features.check("jpg_2000"), features.check("libtiff"), features.check("littlecms2").icc_profile=im.info.get("icc_profile"), exif=im.getexif() or im.info.get("exif"), xmp=im.info.get("xmp"), and format-specific options when saving.ImageSequence.Iterator(im) and save with save_all=True plus append_images=[...]; otherwise many formats save only the first frame.Run the bundled report when behavior depends on optional libraries or registered extensions:
python sub-skills/formats-and-metadata/scripts/format_capability_report.py --json
Or in Python:
from PIL import features
required = ["jpg", "zlib", "webp", "avif", "jpg_2000", "libtiff", "littlecms2"]
missing = [name for name in required if not features.check(name)]
Use python -m PIL for Pillow's verbose built-in report. Use python -m PIL --report when supported and a shorter report is enough.
from PIL import Image, ExifTags
with Image.open("input.jpg") as im:
im.load()
exif = im.getexif()
orientation = exif.get(ExifTags.Base.Orientation)
icc = im.info.get("icc_profile")
im.convert("RGB").save("output.jpg", quality=90, exif=exif, icc_profile=icc)
After copy(), convert(), resize(), or many compositing operations, format, fp, and format-specific attributes may be absent. Carry needed info, EXIF, ICC, XMP, palette, duration, and loop values yourself.
from PIL import Image, ImageSequence
with Image.open("animation.gif") as im:
frames = [frame.copy().convert("RGBA") for frame in ImageSequence.Iterator(im)]
durations = [frame.info.get("duration", im.info.get("duration", 0)) for frame in ImageSequence.Iterator(im)]
frames[0].save(
"animation.webp",
format="WEBP",
save_all=True,
append_images=frames[1:],
duration=durations,
loop=im.info.get("loop", 0),
lossless=False,
quality=85,
)
Keep the source image open while iterating lazy frames. Copy frames that must outlive the source file.
PNG for lossless RGB/RGBA, alpha, palettes, text chunks, ICC, and PNG EXIF; it needs zlib support.JPEG for lossy photos without alpha; convert RGBA/LA/P with transparency to RGB after choosing a background or dropping alpha intentionally.GIF for palette animation and broad compatibility; expect palette and mode changes across frames.TIFF for multi-page documents, high-bit-depth, tags, and archival workflows; compressed TIFF depends on libtiff.WEBP for modern lossy/lossless stills or animations with optional ICC/EXIF/XMP; behavior depends on libwebp.AVIF for compact modern stills/sequences; encoder choices and availability vary by libavif codecs.JPEG2000 for JP2/J2K workflows; support depends on OpenJPEG and advanced options are strict.PDF/EPS for document outputs with limited image semantics; EPS rasterization may require Ghostscript.Image.info, EXIF, ICC, XMP, palettes, TIFF tags, and multi-frame handling.