Extended thumbnail control in WordPress

A really annoying problem in WordPress is that there is no good control over the thumbnail generation. The only thing that can be controlled is whether the image should be cropped or just resized, and then to what size. WordPress has a built-in thumbnail editor, but it doesn’t work in the “custom” sizes (at the time of writing, WordPress version 3.05).

The problem is that it is possible to get WordPress to crop and generate thumbnails, but they are always centred in both the X and Y axis. Very annoying! A good example is this page; When an image is uploaded to the portfolio, you don’t want it to centre the image, as this usually results in seeing a lot of text. What you want to show is what the page looks like from the top, as that is the first impression the visitor encounters.

Fortunately, there is thumbGen. ThumgGen is a plugin for WordPress dedicated to developers. In other words, it doesn’t do anything if you just install it, but is meant to work behind the scenes.

Here is the code for the plugin in the ‘Portfolio’ section:

" title="">" alt="" />&gt
  

Here you first check if there is a thumbnail associated with the post. If there is, then it creates a thumbnail that is centred in the X-axis, and starts from the top in the Y-axis. This image is then linked to the “big” version of the image.

And yes, this code snippet jumps back and forth between PHP and HTML. Easier to copy-paste and use for other purposes then 😉

Loading