WP Manifestindependent plugin directory
manifest / performance / squeeze-image-optimizer-plugin

Squeeze Image Optimizer

WordPress plugin that resizes, recompresses and optionally converts Media Library images (JPEG/PNG/WebP) using WordPress's own image editor APIs — no external services or API keys. Includes automatic optimisation on upload, a batched bulk tool for existing libraries, safe backups with configurable expiry, and transparency-aware format conversion.

by Ink & Water · github.com/inkwaterpaul/squeeze-image-optimizer-plugin · website

★ 0stars
0forks

Install

No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:

wp plugin install https://github.com/inkwaterpaul/squeeze-image-optimizer-plugin/archive/refs/heads/main.zip

A WordPress plugin that resizes, recompresses and optionally converts images already in — or newly added to — your Media Library. Built entirely on WordPress's own image editor API (Imagick where available, GD otherwise), so there's no external service, no API key, and no per-image fee.

Features

  • Max width and quality settings, same mental model as a desktop image tool
  • Never upscales — only ever shrinks an image that's wider than your cap
  • Skips files already under a size threshold, so re-runs are fast
  • Keeps the original if the "optimised" result would be bigger — never trades a worse result for a smaller one
  • Optional format conversion (PNG → JPEG, or PNG/JPEG → WebP), with a guard so a transparent PNG is never silently flattened onto a black background by a JPEG conversion
  • Automatic optimisation of new uploads, applied before thumbnails are generated so core never does the resize twice
  • A bulk tool for your existing library, processed in small batches so it survives hosting execution-time limits on libraries of thousands of images — with a live progress bar, ETA, and a per-image error log
  • Backups with expiry — the original is kept the first time an image is touched, with one-click restore from the Media Library, an automatic expiry window (7/14/30/90 days, or forever), and a manual "delete all backups now" option
  • Post content kept in step with conversions — when an image changes format, its URLs (full size and every thumbnail size) are updated in post, page, pattern and template content automatically, so Image and Cover blocks don't break
  • A conversions log — every format change is listed with how many posts were updated, plus a ready-to-copy wp search-replace command for URLs stored outside post content

Requirements

  • WordPress 5.8+
  • PHP 7.4+
  • Imagick (recommended) or GD — most hosts have one of these already

Installation

  1. Download or clone this repo into wp-content/plugins/squeeze-image-optimizer, or zip it up and upload via Plugins → Add New → Upload
  2. Activate the plugin
  3. Go to Media → Image Optimizer to configure settings and run the bulk tool

How it works

The plugin leans entirely on wp_get_image_editor() — the same abstraction WordPress core uses to generate thumbnails — rather than shelling out to external binaries or calling a third-party API. That keeps it portable across hosts and means there's nothing to configure beyond the plugin's own settings.

  • New uploads are intercepted via the wp_handle_upload/wp_handle_sideload filters, before any attachment post or thumbnail sizes exist, so the smaller/converted file is what every registered size gets generated from.
  • Existing attachments go through the bulk tool, which backs up the original once, resizes/recompresses/converts, regenerates thumbnail sizes, and records size-saving stats against the attachment.
  • Format conversion changes file URLs. Core blocks such as Image and Cover save the image URL into the post content itself rather than looking it up by attachment ID, so after converting, the plugin rewrites those URLs in post_content (posts, pages, synced patterns, block-theme templates; not revisions). Old resized copies are then deleted, and restoring an original reverses the update. URLs stored anywhere else — page-builder data in post meta (e.g. Elementor), widgets, theme options — are not updated, because that data is often PHP-serialized and a plain replace would corrupt it, so they'll break until you run the WP-CLI commands from the Conversions Log tab. Clear any page cache after a conversion run.

Important notes

  • Auto-optimise-on-upload doesn't keep a backup — there's no attachment yet to attach one to at that point in the upload process. Use the bulk tool if you want a backup kept.
  • Backup expiry runs once a day, not instantly, so a backup can outlive its configured window by up to 24 hours. Restoring an image deletes its own backup immediately afterwards.
  • Animated GIFs are always left alone — recompressing one through a static image pipeline would collapse the animation.
  • The "Optimised" status column only shows in Media Library List view, not the default Grid view.
  • Test format conversion on staging first, especially on a site with a lot of older hand-edited content.
  • If your host offloads media to an actual S3 bucket (e.g. via WP Offload Media), note that this plugin assumes direct filesystem access — it hasn't been built against stream-wrapper-based offload setups. It works unmodified on hosts (like WP Engine) where storage is AWS-backed underneath but presented as an ordinary local filesystem.

Changelog

See CHANGELOG.md.

License

GPL v2 or later.