A simple, local image only, thumbnail generation script with a file based cache and optional browser based cache.
Firstly, make sure your cache directory is writable, then access the script like so:
<img src='thumb.php?src=./images/photo.jpg&size=400x300' />
Key | Example Value | Default | Description |
---|---|---|---|
src | ./images/photo.jpg | Absolute or relative path to the source image, no URLs allowed | |
size | 100, 100x200, 100x, x100, <500 | 100 | Width and/or height must be between 8 and 1500 |
crop | 0 - 1 | 1 | 0 = Displays the entire image within the canvas 1 = Crop the image so that the entire canvas is used |
trim | 0 - 1 | 0 | 0 = Displays white space for unused canvas 1 = Removes any white space |
zoom | 0 - 1 | 0 | For when the size of the canvas is larger than the original image size 0 = Will not enlarge image 1 = Enlarges image beyond the original image size |
align | c, t, r, b, l, tl, tr, br, bl | c | Alignment of image when cropped |
sharpen | 0 - 100 | 0 | Percentage strength of the image sharpness, based on the percentage midpoint of 12 (strong) and 28 (weak) |
Value | Description |
---|---|
250 | Creates a square image 250px in width and 250px in height |
250x400 | Creates an image 250px in width and 400px in height |
250x | Creates an image with a width of 250px and the height will be automatically calculated to maintain the aspect ration of the original image |
x250 | Createse an image with a height of 250px and the width will be automatically calculated to maintain the aspect ration of the original image |
<800 | Creates an image where the width or height does not exceed 800px. For landscape images the width will be 800px and the height will be automatically calculated, and for portrait images the height will be 800px and the width will be automatically calculated. |
If you're dealing with images straight from a camera, some may contain EXIF data which specifies the original orientation the image should be viewed at.
To enable this feature, change the constant ADJUST_ORIENTATION
to true
.
More information, and an in depth analysis of EXIF Orientation can be found in this article written by @recurser