SLIR (Smart Lencioni Image Resizer) resizes images, intelligently sharpens, crops based on width:height ratios, color fills transparent GIFs and PNGs, and caches variations for optimal performance.
For questions or support, please visit the SLIR Google Group. If you have found a bug, please use the issue tracker.
- PHP 5.1.2+
- GD Graphics Library -- must be a version that supports
imageconvolution()
, such as the bundled version
Download and unpack to a directory in your web root. I recommend putting SLIR in /slir/
for ease of use. For example, if your website is http://yourdomain.com
, then SLIR would be at http://yourdomain.com/slir/
.
After you have SLIR downloaded, visit http://yourdomain.com/slir/install/
in your favorite web browser.
To use SLIR, place an <img\>
tag with the src
attribute pointing to the path of SLIR (typically "/slir/") followed by the parameters, followed by the path to the source image to resize (e.g. <img src="/slir/w100/path/to/image.jpg"/>
). All parameters follow the pattern of a one-letter code and then the parameter value:
Parameter | Mearning | Example |
---|---|---|
w | Maximum width | /slir/w100/path/to/image.jpg |
h | Maximum height | /slir/h100/path/to/image.jpg |
c | Crop ratio | /slir/c1x1/path/to/image.jpg |
q | Quality | /slir/q60/path/to/image.jpg |
b | Background fill color | /slir/bf00/path/to/image.png |
p | Progressive | /slir/p1/path/to/image.jpg |
f | Fit | /slir/f1/path/to/image.jpg |
Separate multiple parameters with a hyphen: /slir/w100-h100-c1x1/path/to/image.jpg
<img src="/slir/w100-h100/path/to/image.jpg"/>
<img src="/slir/w100-h100-c1x1/path/to/image.jpg"/>
To do this, you simply need to make the crop ratio match up with the desired width and height. For example, if you want your image to be exactly 150 pixels wide by 100 pixels high, you could do this:
<img src="/slir/w150-h100-c150x100/path/to/image.jpg"/>
Or, more concisely:
<img src="/slir/w150-h100-c15x10/path/to/image.jpg"/>
However, SLIR will not enlarge images (except if you enable fitting). So, if your source image is smaller than the desired size you will need to use CSS to make it the correct size.
<img src="/slir/w100-p0/path/to/image.jpg"/>
<img src="/slir/b900/path/to/image.png"/>
<img src="/slir/?w=100&h=100&c=1x1&i=/path/to/image.jpg"/>
Filenames that include special characters must be URL-encoded (e.g. plus sign, +
, should be encoded as %2B
) in order for SLIR to recognize them properly. This can be accomplished by passing your filenames through PHP's rawurlencode()
function.
<img src="/slir/w100/path/to/image%2Bfile.jpg"/>
Fitting does not work with cropping. If you give both c
and f
you'll get and exception.
Usually f
is used in combination with both w
and h
.
<img src="/slir/w100-h50-f1/path/to/200x200image.png"/>
You get a 100x50 image: the source is resized to 50x50 to keep the aspect ratio and centered in the 100x50. The empty space on the left/right is left transparent (or filled with b
color).
<img src="/slir/w1000-h50-f1/path/to/200x200image.png"/>
You get a 1000x50 image: the source is resized to 50x50 and centered. The empty space is filled with transparent/bg color.
<img src="/slir/w600-h400-f1/path/to/200x200image.png"/>
Source image is never enlarged: you will have a final image of 300x200 (aspect ratio of the given size parameters is kept), the source is not resized and the remaining 50 pixels on the left and right are filled with transparent/bg color.
If you would like to support SLIR or to show your appreciation for the time spent developing this project, please make a financial contribution.
For more documentation, open core/slir.class.php
in your favorite text editor.