WordPress image compression and conversion

Shrink images without ever touching the original

Set up an image optimizer WordPress media libraries can trust: scale, convert to WebP or AVIF, and see the real file size before committing — the original file is never overwritten, and Restore brings it back at any time.

  • Original file is never modified — a new optimized copy is created instead.
  • Byte-accurate size estimate before you convert anything.
  • Always compresses from the highest-quality source available.
  • Updates references everywhere — blocks, classic content, page builders.
Image OptimizerMedia Library
hero-banner.jpg
Original Dimensions3840 × 2160
Original Size2.4 MB
Restorable OriginalYes
Resolution60%
Quality75%
Output Format
Keep OriginalJPEGWebPSupportedAVIFSupported
Estimated Size480 KB
Reduction−80%
Savings1.9 MB
80%
RestoreConvert
Quick answer

Image optimizer WordPress: what does the module actually do?

This is what an image optimizer WordPress media libraries get with TheOneWP: an "Optimize" action on every image in the Media Library opens a modal to scale by percentage and convert to JPEG, PNG, WebP or AVIF. TOWP_Image_Optimizer compresses from the highest-quality source available — bypassing WordPress's own scaled-down upload copy when a true original exists — creates a new _opt file rather than overwriting anything, regenerates every WordPress thumbnail size from that same high-quality source, and rewrites references across Gutenberg blocks, classic content, and page-builder-safe database fields. A live, byte-accurate estimate shows the real output size before you commit, and Restore brings the untouched original back at any time.

The oversized-upload problem

Media libraries fill up with images nobody resized

A camera or phone photo dropped straight into WordPress is often several megabytes larger than the page actually needs, multiplied across every thumbnail size WordPress generates from it.

A destructive optimizer is a real risk

A tool that overwrites the original file the moment you convert it leaves no way back if the compressed result turns out worse than expected.

Format conversion can silently break other tools

Page builders and themes that store a direct reference to an image's URL can end up pointing at a file that no longer exists once a conversion changes its name.

A unified WordPress solution

Compress with a way back, and nothing left broken

The module treats the original as sacred, estimates honestly, and updates every reference that needs to know about the change.

The original is never touched

A new file is created for the optimized version; the source stays exactly as uploaded.

A real estimate, not a guess

The reported size comes from an actual compression pass at the requested settings.

References updated everywhere

Blocks, classic content, and page-builder-safe database fields all get the new URL automatically.

Verified feature set

The complete image optimizer WordPress feature set

Every capability below is present in the class's optimize, estimate, or restore logic.

Formats

JPEG, PNG, WebP and AVIF

WebP and AVIF only appear when the server's GD library genuinely supports them — checked, not assumed.

function_exists() checked4 formats
Accuracy

Byte-accurate live estimate

An actual dry-run compression reports the real output size, with a specific correction for a documented same-format, quality-100 sizing bug.

Real compression passDocumented fix
Quality

Highest-quality source, every time

Compression and thumbnail regeneration both use the true pre-scaling original when WordPress created a scaled-down upload copy.

original_image detectionAll sizes regenerated
Propagation

Site-wide, page-builder-aware URL updates

Covers Gutenberg blocks, classic content, srcset, and database rows — while deliberately skipping post-meta rewrites for the main URL to protect Bricks/Elementor-style stored references.

Multi-source rewriteBuilder-safe
Recovery

One-click Restore

Brings back the untouched original file and its original metadata at any time after optimizing.

towp_img_restoreMetadata snapshot
Recommended workflow

Optimize an image optimizer WordPress upload in four steps

Check the estimate before committing, and know Restore is always available after.

01

Click "Optimize" in the Media Library

Available as a row action on any image, and inside the attachment edit screen.

02

Set scale, quality and format

Watch the live estimate update as you adjust each setting.

03

Convert and check the result

The new file replaces the reference everywhere the image appears on the site.

04

Restore if the result isn't right

One click brings back the exact original file and its metadata.

Practical use cases

Where safe compression actually matters

The module fits sites where image weight affects load time but mistakes need to be reversible.

Photography-heavy sites

Large camera uploads get scaled and converted to WebP without losing the original file as a fallback.

Sites chasing Core Web Vitals

Smaller, modern-format images reduce page weight directly, with an estimate to confirm the trade-off before converting.

Existing media libraries with years of uploads

Go back through older, oversized images without any risk of losing the source file for good.

Operational benefits

Compression that respects what was there before

Every design choice in the verified code favors reversibility and quality over an aggressive default.

Always reversibleNothing about optimization is a one-way door — Restore is available for as long as the backup exists.
Every thumbnail size improves tooRegeneration from the high-quality source means small sizes aren't stuck compounding earlier compression.
Page builders stay intactThe deliberate post-meta exception protects Bricks- and Elementor-style stored URL references.
No stale files left behindRe-optimizing in a different format removes the previous _opt file instead of accumulating copies.
Performance behaviour

Smaller images, correctly cached

The verified implementation makes sure a converted image is actually seen as new by browsers and caches.

Version-bumped URLs after every change

Optimizing or restoring bumps a version marker so cached copies of the old file don't linger in browsers or CDNs.

Assets load only where the modal is used

The optimizer's own CSS and JS enqueue only on the Media Library and post editor screens.

Memory limit raised only when needed

wp_raise_memory_limit( 'image' ) is called specifically around the compression work, not globally for the whole request.

Security implementation

Administrator-only, every single action

Every AJAX endpoint that touches a file or the database requires the same strict capability.

01

manage_options on every AJAX action

Info, estimate, optimize and restore all require this capability, alongside a verified nonce.

02

MIME type validated before processing

Only JPEG, PNG, GIF, WebP and AVIF sources are accepted — anything else is rejected before any file operation runs.

03

Sanitized filenames throughout

File names read from metadata pass through sanitize_file_name() before being used to build a file path.

04

Format support checked server-side, not trusted from the request

A requested format is validated against what the server's GD library can actually produce before any conversion starts.

Verified compatibility

Aware of how WordPress actually stores images

The supplied code accounts for WordPress's own upload-time scaling and how popular page builders store image references. No compatibility claim beyond the verified implementation is assumed.

Core behavior

WordPress's own upload scaling

Detects the original_image metadata WordPress records when it scales a large upload down, and uses that true original as the compression source.

original_imageFull-resolution source
Page builders

Bricks & Elementor-style storage

Handles both plain and JSON-escaped URL formats in the database, matching how these builders serialize layout data.

JSON-escaped URLsPostmeta-safe
Rendering

render_block_core/image

Used specifically because WordPress 6.x's own block image renderer doesn't call the function core normally uses for size URLs — a targeted fix for a real gap.

Gutenberg-specificWP 6.x
Solution comparison

TheOneWP versus common alternatives

Compare a real image optimizer WordPress implementation with typical dedicated image-compression plugins.

CapabilityTheOneWP Image OptimizerOther common solutions
Original file safety Never overwritten; a separate optimized file is createdSome plugins overwrite the original directly
Size estimate Real compression pass, byte-accurateOften a rough percentage estimate
Compression source True highest-quality original, even past WP's own scalingMay compress from whatever file WordPress already scaled down
Page builder safety Deliberate exception protects Bricks/Elementor referencesVaries; some tools can break stored builder references
Restore Full original file and metadata, one clickNot always available once a conversion is applied
Administration Built into the Media Library, no separate screenMay require a dedicated bulk-optimization dashboard
Best practices

Compress with confidence, not guesswork

A few habits get the most out of a non-destructive optimizer.

01

Check the estimate before converting

Confirm the trade-off between size and quality actually makes sense for that specific image.

02

Prefer WebP or AVIF when the server supports them

Both typically produce a smaller file than JPEG at comparable visual quality.

03

Use Restore freely while testing settings

Since the original is always kept, there is no real cost to trying a setting and reverting if it doesn't look right.

04

Re-check pages built with a page builder after converting

The safeguards are real, but a visual check after a big batch of conversions costs little.

Common mistakes

Avoid assumptions the code does not support

The module has a defined, verified scope — a few assumptions outside it cause confusion.

Expecting an animated GIF to stay animated

Optimizing a GIF flattens it to a static image — the warning shown before converting one exists specifically because this cannot be undone by re-optimizing.

Assuming WebP or AVIF is always available

Both depend on the server's GD build; if the check fails, that format simply won't appear as an option.

Deleting the attachment and expecting the backup to remain

Removing the image itself also removes its backup folder — Restore only works before the attachment is deleted.

Frequently asked questions

Image Optimizer FAQ

These answers come directly from the verified class and its optimize/estimate/restore logic.

Does optimizing an image delete or overwrite the original file?

No. The module creates a new {name}_opt.{extension} file and updates every reference to point at it — the original file is never modified, and stays available for the Restore action at any time.

What does it actually compress from — the file I uploaded, or a WordPress thumbnail?

The highest-quality version available. If WordPress scaled your upload down on the way in, the module detects the true pre-scaling original and compresses from that, then regenerates every WordPress-generated thumbnail size from that same high-quality source too, instead of re-compressing an already-lossy copy.

Can I see the file size before committing to a conversion?

Yes. A live estimate runs the actual target scale, quality and format through a real compression pass and reports the genuine byte count — not a mathematical guess.

Why does the estimate behave differently at 100% quality and the same format?

Because re-encoding an already-compressed JPEG at GD's quality 100 uses different quantization tables than a camera's own JPEG encoder and can produce a dramatically larger file for no visual gain. In that specific case the module estimates by scaling the real original file size by area instead of re-encoding.

Does converting to WebP or AVIF break pages built with Elementor or Bricks?

The module specifically excludes the main image URL from post-meta rewriting when updating the database, because page builders like these store the original URL as a direct reference — only the file itself and its content-embedded references get updated, protecting builder-specific meta from corruption.

What happens to an animated GIF?

It gets flattened to a static image during optimization, and the module shows a clear warning about this before you convert one, since the animation cannot be preserved.

Are WebP and AVIF always available as conversion targets?

Only if the server's GD library actually supports them — checked with function_exists() for imagewebp() and imageavif() specifically. If the server can't produce one of those formats, it simply doesn't appear as an option.

What happens to the backup if I delete the image entirely?

It gets cleaned up automatically. The delete_attachment hook removes the corresponding backup folder so a deleted image does not leave an orphaned original behind.

Stop choosing between smaller and safe.Get both, with a real way back.

Use an image optimizer WordPress media libraries can trust: byte-accurate estimates, the highest-quality source every time, and an original that's never actually gone.