Dynamically Resize WordPress Images On-the-Fly

November 15, 2011 — 1

Creating multiple image sizes in WordPress is quite easy when the image is attached to a post or page. Theme.fm has an excellent write up on how to do this with the add_image_size function. The problem with this method is that it creates a lot of bloat because for every image uploaded it’s sized to this new size even if you’re not going to use it. Also getting the different available sizes from just a url is a pain.

To side step this issue Theme and Plugin developers have resorted to using scripts like TimThumb , which recently have a major vulnerability discovered. Another script that can generate images on the fly is called vt_resized. This script is nice because it uses native WordPress functions to generate the new image. The only is issue is that it does not support WordPress Multisite. Here’s a modified version of the script with crude multisite support.

If you find a bug let me know. Hopefully WordPress will provide a similar function in the WP core in the future.