Optimize a media item is a WordPress ability from Imagify — usable via Easy MCP AI, which connects Claude, ChatGPT, and any AI assistant to your site.
Install Free Plugin →Optimize a media item
DestructiveOptimizes (or re-optimizes) a specific media library attachment on demand.
Requires the Imagify plugin on WordPress 6.9+ for the Abilities API (abilities are registered only when the wp_register_ability() function exists). Most abilities are gated by the Imagify 'manage' capability, resolved through Imagify's own capability abstraction (honors the imagify_capacity filter and multisite network-admin logic; equivalent to manage_options by default); the bulk-optimize, generate-missing-nextgen, and restore-media abilities instead check the WordPress 'manage_options' capability directly.
What it does
This ability triggers Imagify's optimization process for a single WordPress media attachment, overwriting its file with the compressed result — first-time optimization if the media hasn't been processed yet, or re-optimization if it has. An optional optimization_level (0 = normal, 1 = aggressive, 2 = ultra) can override the site's default for this call. The call is gated by a credit-consumption guard: calling it without confirm=true returns a status of confirmation_required (with a preview of the credit cost) instead of running the optimization, and the caller must resend the request with confirm: true to proceed; the guard can also short-circuit with insufficient_quota or invalid_api_key if the account can't support the call. Because the underlying process runs as a background job, the returned optimized_size may read 0 immediately after the call resolves; polling get-media-status confirms the final result. Use this to optimize an image right after upload or to force a re-compression pass with a different aggressiveness level, instead of clicking through the Media Library UI.
See it in action
You ask your AI assistant
"Optimize media attachment #4821 using the aggressive optimization level."
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| media_id | integer | Yes | The WordPress attachment ID to optimize. |
| optimization_level | integer | No | Optimization level: 0 (normal), 1 (aggressive), or 2 (ultra). If omitted, uses the site's global setting. |
| confirm | boolean | No | Set to true to execute after reviewing the credit-consumption preview returned by a prior call without this flag. Defaults to false. |
Returns
An object with 'status' (success, error, confirmation_required, insufficient_quota, or invalid_api_key), 'original_size' and 'optimized_size' in bytes (null on error, and optimized_size may be 0 immediately after the call while the background job finishes), 'savings_percent', and 'error_message' (null on success).
Permission
The current user must have the Imagify 'manage' capability.
More Imagify abilities
Bulk optimize
Schedules a bulk image-optimization run across the WordPress media library or Imagify's custom folders.
Generate missing next-gen versions
Queues generation of missing WebP/AVIF versions for every already-optimized image on the site.
Get account status
Reports the connected Imagify account's plan, quota consumption, and API key validity.
Get media optimization status
Retrieves the optimization status and size metrics for a single media library attachment.
Get next-gen format coverage
Reports how many optimized images are still missing a next-gen (WebP/AVIF) version and which next-gen format is configured.
Get optimization statistics
Returns aggregate optimization savings for both WordPress media and custom (non-Media-Library) folders.