Convert images to WebP and swap references

MediaAdvanced~30 minUpdated

Before you start

A connected site with media reads, the upload ability, content reads, and Replace block all enabled. Images in classic-editor content are not blocks, so Replace block cannot reach them and the agent lists them as skipped. Pages are reached only while the Update page tool is on. Posts owned by a page builder are refused. Take a database backup before a run, since this touches both the library and post content: uploads cannot be undone, while the post edits can be reverted from the Changes tab. The re-encoding happens in your AI client, not in the plugin, so the chat app has to be able to download the images and convert them to WebP itself. If it cannot reach your site's files, it cannot run this recipe. Upload media takes base64, which the plugin says is reliable only for small images, and it needs a filename for each upload, so the agent picks one from the original name.

WebP images are usually a good deal smaller than the JPEG or PNG they replace, which is why people want to convert a page full of heavy photos. The realistic version of this job with a governed agent is not a magic optimizer button. The agent re-encodes each image you point it at, uploads the result as a new WebP attachment, and then updates the places in your content that referenced the old file. It is deliberate and batch by batch, and you approve the swaps before any post changes.

Because this both adds to the library and edits post bodies, it earns the two-pass, wait-for-approval flow.

The prompt
I want to convert [the images in these three posts] to WebP and update the
posts to use them. Be clear with me about scope: I know this re-encodes and
re-uploads each image and swaps the reference, it is not a server-side bulk
optimizer of my existing files.
First pass, change nothing that I have not approved: list the images in scope,
tell me which are worth converting, and for each planned swap show me the old
URL and the post it appears in. Then re-encode those images to WebP and upload
each as a new attachment.
Only after I approve a batch, read each post as raw block markup and replace
the image block that uses the old URL with one that uses the new WebP URL and
attachment id, sending exactly one block and passing its path and core/image as the
expected block name. Work in small batches and show me each batch with the old
image block beside the new one before it saves. List any image that is not in
a block, or whose block is not core/image, as skipped. Do not delete the original attachments. At the end, give me the new
attachment ids and the list of every post you edited.

Why this is safe to run

The planning is all reads and additive uploads. Listing the images and finding the posts that reference them writes nothing to your content, and uploading a new WebP adds an attachment without altering the original. So you get to see every planned reference swap before a post body changes.

The one ability that edits your content is Replace block, which swaps a single image block in a post’s body and checks the block name at that path before it writes. The prompt asks for the old image block with each batch, so a swap can be put back. The post edits are recorded in the Changes tab and can be reverted there until a post is edited again. The uploads are not recorded, so a bad conversion leaves the new files in your library until you delete them yourself. The upload ability takes base64 image data and accepts jpg, png, gif, and webp while rejecting SVG, so the agent cannot slip an unexpected file type into the library. Every ability here stays off until you enable it, each call is checked against the capability of the user you bound the agent to, and every upload and every post edit lands in the Activity Log. If a swap looks wrong, the log points you at the exact post, and the old block markup in the chat lets you put it back.

Already connected? You do not have to paste this at all. Ask your agent for the “convert images to WebP and swap references” recipe, describe the set, and it runs the same approve-first flow on your own site.

How it works

  1. List the images you named and pick the ones worth re-encoding to WebP.
  2. For each one, the agent re-encodes the image and uploads the WebP as a new attachment through the upload ability, which takes base64 image data.
  3. Find the posts that reference the old image URL through a content read, and note the path of each image block.
  4. Show you the planned swaps for a small batch and wait for approval before editing any post.
  5. Replace each approved image block with one that points at the new WebP, in small batches, pausing to show each batch.
  6. Return the new attachment ids and every post it edited so you can review it.

Questions

Is this a one-click bulk image optimizer?
No, and it is important to be clear about that. There is no server-side optimizer here. The agent re-encodes each image it was given, uploads the WebP as a new attachment, and then swaps the reference in your content. It works image by image on the set you approve, not as a background sweep of the whole uploads folder.
What happens to the original images?
They stay in the library. This recipe uploads new WebP attachments and repoints your content at them; it does not delete the originals. Removing the old files is a separate, destructive step you would scope on purpose after you have confirmed the swaps look right.