Tinypng
Overview
Use this skill to compress local image files through the TinyPNG/Tinify HTTP API without installing SDKs or extra packages. Use the bundled shell script on macOS/Linux and the PowerShell script on Windows.
Workflow
- Confirm that
TINYPNG_API_KEYis set in the current environment. - Run
scripts/tinypng.shon macOS/Linux orscripts/tinypng.ps1on Windows. - Pass only
--inputfor default compression. - Add
--width,--height,--convert, or--preserveonly when the user explicitly asks for those operations. - Let the script create a sibling output file when
--outputis omitted.
Default behavior:
- Compress only.
- Keep the original format unless
--convertis provided. - Keep the original dimensions unless
--widthor--heightis provided. - Do not preserve metadata unless
--preserveis provided. - Do not overwrite the source file by default.
Resize behavior:
- If both
--widthand--heightare provided, the script uses TinyPNG'sfitresize mode. - If only one dimension is provided, the script uses TinyPNG's
scaleresize mode because the HTTP API requires that for single-dimension resizing.
User Usage Guide
Natural-language examples:
- "Compress this image with TinyPNG."
- "Compress this image and set the width to 128."
- "Compress this PNG and convert it to WebP."
- "Compress this JPEG and preserve the creation metadata."
Explicit skill examples:
- "Use
$tinypngto compresshero.png." - "Use
$tinypngto compressphoto.jpgand set width to 128." - "Use
$tinypngto convertbanner.pngto WebP."
Shell examples:
export TINYPNG_API_KEY="your-api-key"
./scripts/tinypng.sh --input ./hero.png
./scripts/tinypng.sh --input ./hero.png --width 128
./scripts/tinypng.sh --input ./banner.png --width 128 --height 128
./scripts/tinypng.sh --input ./banner.png --convert webp
./scripts/tinypng.sh --input ./photo.jpg --preserve creation,location
./scripts/tinypng.sh --input ./hero.png --output ./hero-optimized.png
PowerShell examples:
$env:TINYPNG_API_KEY = "your-api-key"
powershell -ExecutionPolicy Bypass -File .\scripts\tinypng.ps1 --input .\hero.png
powershell -ExecutionPolicy Bypass -File .\scripts\tinypng.ps1 --input .\hero.png --width 128
powershell -ExecutionPolicy Bypass -File .\scripts\tinypng.ps1 --input .\banner.png --width 128 --height 128
powershell -ExecutionPolicy Bypass -File .\scripts\tinypng.ps1 --input .\banner.png --convert webp
powershell -ExecutionPolicy Bypass -File .\scripts\tinypng.ps1 --input .\photo.jpg --preserve creation,location
powershell -ExecutionPolicy Bypass -File .\scripts\tinypng.ps1 --input .\hero.png --output .\hero-optimized.png
Script Details
Script entrypoints:
scripts/tinypng.shscripts/tinypng.ps1
Supported flags:
--input <file>--output <file>--width <n>--height <n>--convert <webp|avif|jpeg|png>--preserve <copyright,creation,location>--help
Output naming:
- If
--outputis omitted, the script writes a sibling file with.tinypnginserted before the extension. - If
--convertis provided and--outputis omitted, the generated file extension matches the requested format.
Notes
- Require
curlto be available in the environment. - Read the API key from
TINYPNG_API_KEY. - Surface TinyPNG HTTP errors directly so the caller can diagnose auth, rate-limit, or request issues quickly.