π Squeezes images. Spills no ink, sends no bill.
Features Β· Screenshots Β· Requirements Β· Installation Β· Privacy Β· FAQ Β· Developers Β· Changelog Β· Contributing Β· Support
Takopic optimises the images of your WordPress media library with the libraries of your own server: jpegoptim,
optipng or oxipng, pngquant, cwebp and avifenc, or GD and Imagick for the WebP and AVIF formats. Free and
unlimited, no API key, no quota: your images never leave your server.
Optimisation
- Compresses JPG and PNG images in place, and creates their WebP and AVIF versions, kept only when lighter.
- Keeps the original images, to restore them at any time.
- Strips the metadata (camera, date, GPS position), but keeps the colour profile when the colours need it.
- Handles CMYK JPGs and the photos stored sideways.
Media library
- Optimises the images on upload, or the whole library in the background, with pause and cancel.
- Re-optimises the images left behind by new settings or new image sizes of the theme.
- Shows the status, the errors and the bytes saved of each image, and optimises or restores it in one click.
On the site
- Serves AVIF and WebP with the JPG or PNG as fallback: in a
<picture>element, or from the server with rewrite rules (Apache, nginx). - Tests the delivery.
For developers
takopic_image()andtakopic_image_sources()give the<picture>of an image or its srcsets, in your own templates.- WP-CLI:
wp takopic run,clean,restore,statsandhealth. - Filters for the folder of the originals, the priority and threads of the libraries, the pace of the background jobs and the path of a library.
All of them are documented in Developers.
WordPress 6.2 and PHP 8.2 or later, and PHP allowed to run the libraries of the server (proc_open() or exec()):
| Format | Library | Without it |
|---|---|---|
| JPG | jpegoptim |
Not compressed |
| PNG | optipng or oxipng (faster) |
Not compressed |
| PNG lossy (optional) | pngquant |
Lossless only |
| WebP | cwebp |
GD or Imagick, with heavier PNG graphics |
| AVIF | avifenc |
GD or Imagick (WordPress 6.5+), with less sharp colours |
- On Debian or Ubuntu:
sudo apt install jpegoptim optipng webp libavif-bin. - On Windows: no JPG and PNG compression. For WebP and AVIF, put the official builds of
cwebpandavifencon thePATH, or set their path with thetakopic_binary_pathfilter.
In Plugins > Add New Plugin, search for Takopic, then install and activate it. It is on
WordPress.org.
After installing:
- The new uploads are optimised right away:
Optimise new uploads, ticked by default. - The images already in the library wait in the Optimise tab:
Optimise new imagesoptimises them in the background. - The Overview tab lists the missing libraries, and how to install them.
- WebP and AVIF are not served until you turn them on in the Delivery tab.
With Composer:
git clone https://github.com/Striffly/takopic.git
cd takopic
composer install # The dependencies, in vendor-prefixed/.-
No external request: no API, no tracking. The delivery test only requests the images of the site, from its CDN if they are served by one.
-
No metadata: the optimised images lose it, GPS position included. The originals keep it.
-
Private originals: they are kept in
uploads/takopic/originals-{key}/, the key drawn at random for each site, so their URL cannot be guessed. A.htaccessdenies the web access to that folder on Apache and LiteSpeed. On nginx, add this rule to theserverblock of the site (also given on the Delivery tab):location ^~ /wp-content/uploads/takopic/originals- { deny all; }
-
Originals out of the web root: set their folder with the
takopic_backup_dirfilter, before optimising any image. Takopic does not move the originals already kept: move the folder yourself when you change it.// e.g. next to the web root of a Bedrock site. add_filter('takopic_backup_dir', function () { return dirname(ABSPATH, 2) . '/takopic-originals'; });
By default, yes: the JPG and PNG files are replaced by their compressed version, and the originals are kept in
uploads/takopic/originals-{key}/. Restore original images on the settings page, or Restore original on an image
of the media library, puts them back. To only make the WebP and AVIF versions, untick Compress JPG images and
Compress PNG images on the Settings tab.
Once turned on in the Delivery tab, in one of two ways:
- In the HTML: the images of the content and of
wp_get_attachment_image()(featured images, galleries, most themes) are wrapped in a<picture>element, with the JPG or PNG as fallback. Works everywhere, but may break a layout stylingimgdirectly. In a custom theme, usetakopic_image(). - From the server: the server answers
photo.jpgwith its AVIF or WebP version when the browser reads it. The HTML does not change, and CSS backgrounds are served too. Takopic writes the rules inuploads/.htaccesson Apache and LiteSpeed; on nginx, add these ones:
# In the http block:
map $http_accept $takopic_avif {
default "";
"~image/avif" ".avif";
}
map $http_accept $takopic_webp {
default "";
"~image/webp" ".webp";
}
# In the server block:
location ~* ^/wp-content/uploads/(?<takopic_file>.+\.(?:jpe?g|png))$ {
add_header Vary Accept;
try_files /wp-content/uploads/takopic/formats/$takopic_file$takopic_avif /wp-content/uploads/takopic/formats/$takopic_file$takopic_webp $uri =404;
}A CDN must vary its cache on the Accept header, or serve the JPG to everyone. Test the delivery checks what the
server sends.
Its images are listed as "Older settings": Re-optimise outdated images makes their thumbnails again from the
originals, and optimises them.
The background jobs run the libraries at the lowest priority, behind the requests of the site. On a small server, the filters slow them down further.
Yes for WebP and AVIF, made by GD or Imagick when the libraries are missing. The JPG and PNG compression needs the libraries, which most shared hosts do not let you install: ask your host. The Overview tab tells what is missing.
Deactivated, Takopic stops its background job and removes its rewrite rules: the site serves the JPG and PNG images again. Its settings and files stay, and the rules come back on activation.
Deleted, Takopic removes its settings and data from the database, but leaves the files: the compressed images, their
WebP and AVIF versions and the originals. To get the originals back, run Restore original images before deleting
it.
Before deactivating, a dialog shows how many images Takopic has optimised and the size of uploads/takopic/, with a
button to restore the originals, and warns when the theme calls takopic_image(): its pages break while Takopic is
deactivated. With nothing to warn about, Takopic deactivates at once.
Every optimisation starts from the original image:
# JPG
jpegoptim --strip-all --all-progressive --overwrite --max={quality} photo.jpg
# PNG: optipng, or oxipng when installed
optipng -clobber -strip all -o {level} \
-out photo.png takopic/originals-{key}/photo.png
oxipng -o {level} --strip safe --force --threads {threads} \
--out photo.png takopic/originals-{key}/photo.png
# PNG, lossy compression: pngquant, then optipng or oxipng on tmp.png
pngquant --quality={quality - 15}-{quality} --strip --skip-if-larger --force \
--output tmp.png -- takopic/originals-{key}/photo.png
# WebP
cwebp -q {quality} photo.jpg -o takopic/formats/photo.jpg.webp
# AVIF
avifenc -q {quality} --ignore-exif --ignore-xmp --speed {speed} --jobs {threads} \
photo.jpg takopic/formats/photo.jpg.avifavifencolder than 1.0 gets the quality ascq-level. Its speed is 6 by default.- The libraries run on several files of an image at once, within
takopic_threads(4 on upload, 2 in background jobs):avifencandoxipngget the threads left,{threads}. - A PNG is also tried with
cwebp -near_lossless 60, kept if lighter: graphics and screenshots get much lighter and sharper, photos stay lossy. - Without
cwebporavifenc, GD or Imagick make the WebP at the same quality, and the AVIF at the quality + 5 (up to 89, from 90 as is), close toavifenc. The PNG images are not tried in near-lossless then.
The <picture> option only covers the content and wp_get_attachment_image(). For the images of your own markup,
e.g. from an ACF field, use these functions.
Important
Keep the function_exists() check: without it, the pages break while Takopic is deactivated.
takopic_image() returns the <picture> of an image, whatever the options:
if (function_exists('takopic_image')) {
echo takopic_image($image_id, 'hero'); // Class of the <picture> element.
echo takopic_image($image_id, 'hero', true); // data-src and data-srcset, for a JavaScript lazy loader.
}<picture class="takopic-picture hero">
<source type="image/avif" srcset="takopic/formats/photo.jpg.avif 2500w, β¦" sizes="β¦">
<source type="image/webp" srcset="takopic/formats/photo.jpg.webp 2500w, β¦" sizes="β¦">
<img data-takopic src="photo.jpg" srcset="photo.jpg 2500w, β¦" sizes="β¦" width="2500" height="1667" alt="">
</picture>takopic_image_sources() returns the sources only, for a theme writing its own <picture>: from a srcset or an
image URL, the srcset of each format, keyed by MIME type, best first. A size without a file in a format keeps its JPG
or PNG.
$sources = function_exists('takopic_image_sources') ? takopic_image_sources($srcset) : [];
// ['image/avif' => 'takopic/formats/photo.jpg.avif 2500w, photo-300x200.jpg 300w',
// 'image/webp' => 'takopic/formats/photo.jpg.webp 2500w, takopic/formats/photo-300x200.jpg.webp 300w']
foreach ($sources as $type => $format_srcset) {
printf('<source type="%s" srcset="%s" sizes="%s">', esc_attr($type), esc_attr($format_srcset), esc_attr($sizes));
}| Command | What it does |
|---|---|
wp takopic health |
Checks that the libraries are installed. |
wp takopic run |
Optimises the new images, with the settings of the settings page. |
wp takopic clean |
Removes the WebP and AVIF files. The JPG and PNG files stay compressed. |
wp takopic restore |
Restores the original images and removes every file made by Takopic. |
wp takopic stats |
Prints the bytes saved on the media library. --rebuild measures every image again. |
wp takopic version |
Shows the version of Takopic. |
wp takopic run takes these options, all listed by wp help takopic run:
wp takopic run # Optimises the new images.
wp takopic run --force # Optimises every image again.
wp takopic run --regenerate # Makes the thumbnails again from the originals first, implies --force.
wp takopic run --thumbnails-only # Leaves the full size images out.
# Turns a format off or on: --[no-]jpg, --[no-]png, --[no-]webp, --[no-]avif.
wp takopic run --no-avif
# Overrides a setting of the settings page: --jpg-quality, --png-compression, --png-level,
# --png-lossy-quality, --webp-quality, --avif-quality, --avif-speed.
wp takopic run --webp --no-avif --no-jpg --no-png --webp-quality=75 --force
# Exits with an error when images fail, e.g. in a deployment script.
wp takopic run || exit 1wp takopic stats first measures the images optimised before Takopic counted the bytes saved, from the sizes of their files:
nothing is encoded again.
The folder of the original images. Set it before optimising any image: Takopic does not move the originals already kept. See Privacy to keep them out of the web root.
apply_filters('takopic_backup_dir', string $dir)$dir: the absolute path ofuploads/takopic/originals-{key}.
The priority of the libraries, from 0 (normal) to 19 (lowest). Windows has none.
apply_filters('takopic_nice', int $level, string $context)$level:19in background jobs,0otherwise.$context:'upload','background'or'cli'.
The threads the libraries run on at once, all together: cwebp, jpegoptim, optipng and pngquant take one each,
avifenc and oxipng the threads left.
apply_filters('takopic_threads', int|string $threads, string $context)$threads:4on upload,2in background jobs,'all'(every core) in WP-CLI.$context:'upload','background'or'cli'.
// In a mu-plugin: lighter background jobs on a small server.
add_filter('takopic_threads', function ($threads, $context) {
return $context === 'background' ? 1 : $threads;
}, 10, 2);The seconds a library may take on a file, then it is stopped.
apply_filters('takopic_timeout', int $seconds)$seconds:120.
The path of a library, or false to turn it off. Without cwebp or avifenc, GD or Imagick make the format.
apply_filters('takopic_binary_path', string|null $path, string $name)$path: the one found in the folders of thePATH, then in/usr/bin,/usr/local/bin,/bin,/opt/homebrew/binand/opt/local/bin(PHP-FPM often passes an emptyPATH),nullif none.$name:'jpegoptim','optipng','oxipng','pngquant','cwebp','avifenc'or'nice'.
// A library installed out of the usual folders.
add_filter('takopic_binary_path', function ($path, $name) {
return $name === 'avifenc' ? '/home/me/bin/avifenc' : $path;
}, 10, 2);The seconds a background job runs in one request, before the next request takes over. On multisite, the filter
carries the ID of the site: takopic_2_job_default_time_limit on the site 2.
apply_filters('takopic_job_default_time_limit', int $seconds)$seconds:20.
A pause after each image of a background job, in seconds. On multisite, the filter carries the ID of the site:
takopic_2_job_seconds_between_batches on the site 2.
apply_filters('takopic_job_seconds_between_batches', int $seconds)$seconds:0.
To release Takopic, run its tests or draw its logo, see CONTRIBUTING.md.
Takopic is free, and will stay so. If it saves you time or bytes, you can buy me a coffee β:
- PayPal: paypal.me/striffly
- Bitcoin:
bc1q3j7gxxykpu9zp3sgxyallw0hq0sr659zl35wre
Takopic is developed by ClΓ©ment Gayot.
It started as a fork of Squidge, created by Ainsley Clark in 2021 with contributions from Roman K, Rohinish and karbivskij, and was largely rewritten in 2026. Many thanks to them for the foundations: the idea of relying on the native libraries of the server comes from Squidge.
Thanks also to Media Optimizer by YooHW for some ideas: the menu, the delivery page, the display of the bytes saved, and more.
Takopic is free software, released under the GNU General Public License v3 or later.





