A simple, local image only, thumbnail generation script written in PHP
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE.md Added quality option Jun 9, 2016
README.md Fixed Markdown syntax Apr 21, 2017
composer.json Updated repo name Jun 19, 2014
thumb.php Added check for exif_read_data Nov 4, 2016

README.md

Thumb

A simple, local image only, thumbnail generation script written in PHP with a file based cache and optional browser based cache.

Example Usage

Firstly, make sure your cache directory is writable, then access the script like so:

<img src='thumb.php?src=./images/photo.jpg&size=400x300' />

Query Parameters

Key Example Value Default Description
src ./images/photo.jpg Absolute path, relative path, or local URL to the source image. Remote URLs are not 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)
gray 0 - 1 0 0 = Displays resized image as normal
1 = Converts image to grayscale
ignore 0 - 1 0 0 = Displays resized image as normal
1 = Displays original image file with the animation present

Size Parameter

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.

Automatic Orientation Correction

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 @daveperrett

License

Thumb.php is licensed under the MIT license, see LICENSE.md for details.