Fork me on Github

BFI Thumb

A Timthumb replacement. An on-the-fly WordPress image resizer. Extends and uses the default capabilities of WordPress' Image Editors to add some basic Timthumb capabilities.

You can read the tutorial and get more information about BFI_Thumb from this article: Moving Away From TimThumb to BFIThumb

Download .zip Download .tar.gz

Where do I use this?

You can use this script in your WordPress themes or plugins. The script is safe to be included multiple times in a single WordPress site by different plugins and themes. When multiple versions of BFI_Thumb are found within a site, the newest version will be used.

This means that if you use bfi_thumb in your WordPress theme, and some plugins you also have activated use bfi_thumb, they would all work without any problems.

How do I use it? (Usage)

1. Download the script (click link above)

2. Include BFI_Thumb.php into your WordPress files.

Your functions.php file is a good place for this


3. Call bfi_thumb on your image and get your new URL

$params = array( 'width' => 400 );
$image = bfi_thumb( "", $params );
echo "<img src='$image'/>";

The above outputs:

<img src=''/>

What is BFI Thumb?

BFI Thumb is a small PHP script that you include in your WordPress theme or plugin then gives you the ability to resize-crop and apply filters on-the-fly to your images with a simple PHP function call.

Why do you need this?

Aqua Resizer is awesome, WP's Image Editor is awesome, Timthumb is awesome.

But when WP reached 3.5 and introduced the Image Editor class, as a theme author I couldn't anymore use Timthumb in my WP themes. An alternative was to use Aqua Resizer instead. Although it did the job quite well, I needed some of the functionalities supported by Timthumb.. I needed to be allowed to grayscale and color tint images and resizing them at the same time. I couldn't find anything that did everything I wanted, so I made BFI_Thumb.

Okay.. so what does BFI Thumb do?

  • Replacement for Timthumb and other third-party image resizers
  • Processes on-the-fly
  • Easy to use
  • Uses WP's classes
  • Resize up & down with cropping
  • Outputs a clean URL of the processed image
  • Reuses previously processed images
  • If the original image was changed it will be processed again
  • Stores images in the uploads folder for security
  • Apply image filters:
    • Grayscale
    • Tint/Colorize
    • Negate
    • Opacity

Advanced Usage

// Resize by width only
$params = array( 'width' => 400 );
bfi_thumb( "", $params );

// Resize by height only
$params = array( 'height' => 300 );
bfi_thumb( "", $params );

// Resize by width and height
$params = array( 'width' => 400, 'height' => 300 );
bfi_thumb( "", $params );

// Crop
$params = array( 'width' => 400, 'height' => 300, 'crop' => true );
bfi_thumb( "", $params );

// Change opacity (makes your image into a PNG)
$params = array( 'opacity' => 80 ); // 80% opaque
bfi_thumb( "", $params );

// Grayscale
$params = array( 'grayscale' => true );
bfi_thumb( "", $params );

// Colorize
$params = array( 'color' => '#ff0000' );
bfi_thumb( "", $params );

// Negate
$params = array( 'negate' => true );
bfi_thumb( "", $params );

// Multiple parameters
$params = array( 'width' => 400, 'height' => 300, 'opacity' => 50, 'grayscale' => true, 'colorize' => '#ff0000' );
bfi_thumb( "", $params );

Where are the images stored?

Bfi_thumb stores previously created images in WP's default uploads directory in the subdirectory bfi_thumb, and uses those for future calls. The script automatically checks for updates on the original image then re-creates new images when needed. Any image can be used as long it is in your WordPress instance. Remote images are not supported due to security concerns.


A hash is appended to the end of the filename, this hash represents the resize dimensions, filters applied to the image as well as the modified date of the source image. This means that correct processed image is always fetched for future bfi_thumb calls. An added benefit is that when the source image is updated, the hash changes, thus prompting the script to process it again.

You can change the location of where the images are saved by defining this constant anywhere in your code:

// Change the upload subdirectory to wp-content/uploads/other_dir
@define( BFITHUMB_UPLOAD_DIR, 'other_dir' );


BFI Thumb is created by @bfintal.

Follow me in Twitter @bfintal and @gambitph.