PHP Imager makes image management easier when it comes to manipulating, caching and customizing images. It has a WordPress twin, WP-Imager
Uses TimThumb for image resizing and caching
Caches images in a custom folder, to avoid clutter
- PHP 5.2.x or higher
- GD image library
- Place the provided
cache_img
folder in your site's root folder.
Make sure that
cache_img/cache
is writable, in case images are not displaying.
- Include
php-imager.php
where you need it.
<?php include 'php-imager.php'; ?>
If you want to have pretty img urls, then there's an extra step:
- If you don't have an
.htaccess
yet, place the one provided in your site's root folder.- If you already have an
.htaccess
, then adapt it, following the one provided.
If you don't complete every step the script won't work.
<?php
php_imager($width=null, $height=null, $imgurl=null, $nohtml=false, $class=null, $crop=null, $bg_color=null);
?>
Parameter | Type | Description & Options | Default |
---|---|---|---|
width |
int | Resize dimension of width (dont put 'px' after size) | 100 |
height |
int | Resize dimension of height (dont put 'px' after size) | 100 |
crop |
int | Type of cropping to perform 0 = Resize to Fit exactly specified dimensions (no cropping) 1 = Crop and resize to best fit the dimensions (default) 2 = Resize proportionally to fit entire image into specified dimensions, and add borders if required 3 = Resize proportionally adjusting size of scaled image so there are no borders gaps | 1 |
class |
string | class name/names to append to image. Separate with space. | NULL |
imgurl |
string | URL of the image (eg. http://www.mysite.com/image.jpg). | NULL |
nohtml |
bool | When false, image is wrapped in its img HTML tag. If true, only the image url is returned. |
false |
bg_color |
int | When using crop value '2' (with borders) you can customize the borders color (the canvas beneath the image). | ffffff |
- Function always returns to avoid yet another parameter, so simply echo it in your code.
- Processed IMG's quality is always 100
- Caching is done in a cache_img folder, in the root of your website (provided)
- Pretty img urls are enabled by default. Adapt the .htaccess provided with the script.
Please refer to its WP twin, WP-Imager
Clearly there are some parameters you cannot use together.
$class
won't do anything if$nohtml = true
5/11/2015
TimThumbs (discontinued): BinaryMoon
Jany Martelli @ Shambix
Released under the GPL v3 License