Compress image
compress_imageCompress PNG, JPEG, WebP, or AVIF images via Tinify.dev, writing a smaller file next to the original or to a specified output path. It never returns larger files, and clearly states when optimization is not possible.
Instructions
Compress a PNG, JPEG, WebP, or AVIF image with Tinify.dev and write the smaller file next to the original (or to output_path). The API never returns more bytes than it received; when it cannot shrink the file the tool says so honestly (optimized: false) instead of pretending.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the image (png, jpg, jpeg, webp, avif; max 40 MB). | |
| overwrite | No | Allow replacing an existing file at the output path. Default false. | |
| output_path | No | Absolute path to write the result. Default: <name>.min.<ext> next to the input. The source image is never overwritten unless output_path points at it AND overwrite is true. | |
| quality_mode | No | balanced (default), best_quality, or lossless. lossless is rejected for JPEG inputs. | |
| target_size_kb | No | Aim for a result at or below this many kilobytes (beta; server rollout). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| width | Yes | ||
| wrote | Yes | Whether a file was written. | |
| height | Yes | ||
| optimized | Yes | false when the API could not shrink the file and returned the original bytes; null when the concept does not apply (resize/crop). | |
| request_id | Yes | Quote this when contacting support. | |
| output_path | Yes | Where the result was written, or null when nothing was written. | |
| saved_bytes | Yes | original_bytes - result_bytes. | |
| result_bytes | Yes | Result size in bytes. | |
| change_percent | Yes | Byte change in percent; negative means smaller. | |
| original_bytes | Yes | Input size in bytes. |