Automatic image sizing with static delivery – WordPress Enhancement

Recently I got fed up trying to convince the operators of a client, for whom we had implemented a wordpress site. The operators, even after we repeatedly asked to upload only relevant sizes for certian positions, were trying to make one size fit for all. Hell, places where thumbnails of 1 to 2K would suffice, were being used up by 30K images, resized by our theme constraints. We were running wordpress on lighttpd.

I was already attracted towards the imagemagick, and we are already on ubuntu server os. So instead of using the php-gd library, I created a wrapper which would run the convert tool of imagemagick and do the resizing for us. Also to keep the aspect ratio as far as possible, I dropped in a bit of AI to detect the target image size, and aspect ratio. Deciding how to resize, and where to crop. I asked my associates to use a regexp replace with the dimensions we were going to use in thumbnails. This code was added to the template pages.


$HTTP["host"] == "wordpress" {
   $HTTP["url"] =~ "^/wp-content/uploads/(.*)(jpg|gif|png)$" {
	server.error-handler-404 = "/img_resize.php"
   server.error-handler-404 = "/index.php"   

This was how I configured our wordpress on lighttpd, yea I know there is nothing fancy there, and the hostname is purposefully taken out. The php code is added as a download Download