--- name: image-compress description: "Image compression and conversion - shrink, resize, convert jpg/png/webp. Runs locally." metadata: { "openclaw": { "emoji": "🖼️" } } --- # Image Compression / Conversion Shrink image file sizes, change dimensions, convert between formats. Everything runs on this machine — photos are never uploaded. ## What it does - **Compress**: reduce file size by quality or resolution, for email and messaging - **Resize**: scale by dimension or percentage - **Convert**: jpg / png / webp (webp is usually smallest) - **Batch**: process a whole folder ## How to run it Use the Bash tool with Python's Pillow — cross-platform and entirely local. ```bash python -c "import PIL" 2>/dev/null || pip install -q Pillow # Single image: quality 75, cap width at 1600px, keep aspect ratio python - <<'PY' from PIL import Image im = Image.open("input.jpg") if im.width > 1600: im = im.resize((1600, int(im.height * 1600 / im.width))) im.convert("RGB").save("output.jpg", "JPEG", quality=75, optimize=True) print("compressed -> output.jpg") PY # Batch: every jpg/png in this folder -> webp python - <<'PY' from PIL import Image import glob, os for f in glob.glob("*.jpg") + glob.glob("*.png"): out = os.path.splitext(f)[0] + ".webp" Image.open(f).save(out, "WEBP", quality=80) print(f"{f} -> {out}") PY ``` ## Working notes - Run `ls -lh` before and after, and tell the user how much was actually saved - Never overwrite the original unless the user explicitly asks — write a new file - PNG transparency is lost when converting to JPG but survives in webp; pick the format based on whether the image has an alpha channel