Easy WP Thumbs
PHP Script
WordPress thumbnails, made easy!
Easy WP Thumbs is a PHP script created with the purpose to make WordPress thumbnails creation process as easy and smooth as possible.
Inspired by TimThumb, is based on WP systems for the maximum compatibility.
Requires at least WordPress 3.5 and PHP 5.2
Supports WP_Image_Editor class, using Imagick where available.
Currently you can see this script implemented in Media Grid and Global Gallery
How to use
- include easy_wp_thumbs.php in the main plugin/theme file
- on common servers you are ready to go, move to step 3.
While on hostings preventing direct files access you must check script status and, eventually, insert FTP/SSH credentials<?php // (optional) setup WP multilang functions to target your multilang domain ewpt_status_panel::$multilang_key = 'your_multilanguage_key'; // print status panel. $wrap_with_form_tag = false if you are putting it in an existing form echo ewpt_status_panel::get($wrap_with_form_tag = false); ?>
- Create thumbnails
// inline PHP function returning static image URL <php easy_wp_thumb($img_src, $width, $height, $quality, $alignment, $resize, $canvas_col, $fx); ?> // alternative way, using parameters array. You may use all of them or only few <?php $params = array( 'w' => (int|bool), 'h' => (int|bool), 'q' => (int), 'a' => (string), 'rs' => (int), 'cc' => (string), 'fx' =>(array), 'get_url_if_not_cached'=> (string|bool) ); easy_wp_thumb($img_src, $params); ?> // Timthumb-like async thumb creation (useful to not weight tons of processes on a single page) <img src="<?php echo 'SCRIPT-URL/easy_wp_thumbs.php?src= &w= &h= &q= &a= &rs= &cc= &fx=' ?>" />
Parameters
Parameter | Default Value | Description |
---|---|---|
$img_src / src | // | Image source. Could be the WP image ID or the image path/url(required) |
$width / w | Image’s width | Thumbnail’s width |
$height / h | Image’s height | Thumbnail’s height |
$quality / q | 80 | Thumbnail’s quality in a scale of 0-100 |
$alignment / a | c | Crop alignment. Possible values: tl, t, tr, l, c, r, bl, b, brc = center, t = top, b = bottom, r = right, l = left |
$resize / rs | 1 | Resize method1 = Resize and crop2 = Resize and add borders3 = Only resize |
$canvas_col / cc | FFFFFF | Background / borders color – use hexadecimal values |
$fx / fx | none | Effects applied to the image
|
$get_url_if_not_cached | false | Whether to return remote thumb URL if image is not cached, to avoid page’s opening slowdowns. Use false or the easy_wp_thumbs.php file URL |
Sizing tips
- If both width and height are not specified, image will have original sizes and recreated with different quality and/or effects
- If only one of them is missing, other will be auto-calculated maintaining image proportions