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
require_once('BFI_Thumb.php');
3. Call bfi_thumb on your image and get your new URL
$params = array( 'width' => 400 ); $image = bfi_thumb( "http://mysite.com/myimage.jpg", $params ); echo "<img src='$image'/>";
The above outputs:
<img src='http://mysite.com/wp-content/uploads/myimage-2tj674icu8n8deljokf2tm.jpg'/>
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( "http://mysite.com/myimage.jpg", $params ); // Resize by height only $params = array( 'height' => 300 ); bfi_thumb( "http://mysite.com/myimage.jpg", $params ); // Resize by width and height $params = array( 'width' => 400, 'height' => 300 ); bfi_thumb( "http://mysite.com/myimage.jpg", $params ); // Crop $params = array( 'width' => 400, 'height' => 300, 'crop' => true ); bfi_thumb( "http://mysite.com/myimage.jpg", $params ); // Change opacity (makes your image into a PNG) $params = array( 'opacity' => 80 ); // 80% opaque bfi_thumb( "http://mysite.com/myimage.jpg", $params ); // Grayscale $params = array( 'grayscale' => true ); bfi_thumb( "http://mysite.com/myimage.jpg", $params ); // Colorize $params = array( 'color' => '#ff0000' ); bfi_thumb( "http://mysite.com/myimage.jpg", $params ); // Negate $params = array( 'negate' => true ); bfi_thumb( "http://mysite.com/myimage.jpg", $params ); // Multiple parameters $params = array( 'width' => 400, 'height' => 300, 'opacity' => 50, 'grayscale' => true, 'colorize' => '#ff0000' ); bfi_thumb( "http://mysite.com/myimage.jpg", $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.
wp-content/uploads/bfi_thumb/imagefilename-a6bo4u5enilq2h5wq8lc0.jpg
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' );
Author
BFI Thumb is created by @bfintal.