Thumbnail Creation via PHP

I got a bit tired of numerous security holes and sheer bulkiness of other thumbnail generation scripts, so decided to build my own from scratch, for local images only. Simply upload, create a writable cache directory and parse the image through the PHP script like so:

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

It's super simple and only 155 lines in total. You can specify the width and height, or just the width so the height will get calculated automatically and vice versa. It also allows you to set a maximum width/height, which is best suited for photo thumbnails.

Features:

  • File based cache
  • Automatic deletion of expired cache files
  • Optional browser based cache via the IF_MODIFIED_SINCE HTTP header
  • Multiple size types
  • Options whether to crop, trim, zoom and set alignment
  • Set sharpness based on a percentage midpoint between two values, so you can specify the strength of the sharpness rather than just turning it on or off

View the code and usage instructions on Github

18-Jul-2012 at 1:00pm
Gravatar
  • (optional)
  • Security Code