1. Michael Bagnall
  2. wp_image_optimizer



WordPress Image Optimizer

An image compressor and content optimizer for WordPress.

  1. Place the optimizer.php file in the document root of your WordPress installation.
  2. Configure for your file system, image dimensions, and database connection.
  3. Execute either via the command line or a browser (command line recommended)

WordPress isn't native tongue to me. That said, I feel as competitent with it as I do any standard PHP content management system not written in an unfamiliar framework. Recently, I had been tasked with optimizing a WordPress site that was front heavy, slow loading, and experiencing a ton of show view times and high bounce rates.

The first thing I noticed were the uncompressed screen captures placed in the posts via a WYSIWYG. These had been "constrained" using image dimensions and not cropped, prepared and compressed prior to use. In addition, no caching mechanism had been implemented to make subsequent loading of pages quick for anonymous users.

Seeing the file size (in megs) issue as the greatest challenge, that is what I sought to solve. I wrote a script that goes through the image folder and compresses and constrains the images to a dimension, and then replaces them in the WordPress posts so that they refer to the new image instead of the older ones. Note that this mechanism I have come up with converts all images to JPEG images, so if you have transparent PNG files on your site, there will need to be some further modification to this script. It will also have the unintended side-effect of altering images on links to external sites. This will be addressed in a future revision. If you wish to make a pull request against this, you can do so at the GitHub link located below the code