PHP Thumbnail Script

A script for converting images to different sizes inline, with support for server caching.


/images/sample.jpg /images/sample.jpg /images/sample.jpg images/sample.jpg

Very useful for creating multiple sizes of image urls from single images. Creates a thumbnail image depending on variables passed to it via get.

Images are cached on the server, so server processing overhead is only needed for the first time the script runs on a particular image.

Usage:

<img src="thumb.php?file=FILE&size=SIZE"> - to size the thumbnail  to fit a square

<img src="thumb.php?file=FILE&sizex=SIZEX&sizey=SIZEY"> - to  size the thumbnail to fit a rectangle

<img src="thumb.php?file=FILE&size=SIZE&quality=QUALITY&nocache=NOCACHE"> -  to set a thumbnails quality 

Where:

  • FILE = the file to retrieve
  • SIZE = the maximum size of the thumbnail in pixels
  • SIZEX = the maximum width of the thumbnail (height adjusted accordingly)
  • SIZEY = the maximum height of the thumbnail (width adjusted accordingly)
  • QUALITY = an integer from 0-100 specifying the resulting jpeg quality of the image
  • NOCACHE = an integer 1 or 0. If set to 1, the cached thumbnail is deleted and recreated (use if the source image changes)

Features:

  • Server caching of images
  • Creation of jpeg thumbnails inline, on the fly
  • Can be used for non-local images, if allow_fopen_url in the php configuration is set to true

Requires:

GD Library

Installation:

The script should work with GD versions 1 and 2, and Linux and Windows servers

Licensed under the GNU Lesser General Public License as published by the Free Software Foundation.
Copyright © 2005 Chris Tomlinson.

Download:

Download thumb.php v1.1

Version Changes:

Changes:
0.1 – first release
0.2 – converted cache thumbnail from png to jpeg
0.3 – fixed error where files weren’t being cached properly
0.4 – allowed non local urls (if allow_url_fopen is on), quality and nocache switches
0.5 – allowed maximum x and y settings (for scaling images to fit non square sizes)
0.6 – allowed tagging of images (with the get query placing the text in the bottom left hand corner of the image)
0.7 – fixed gd_info error for php<4.3
0.8 – added gif support (for gd 2.0.28)
0.9 – now supports native outputting of png, jpg and gif formats
1.0 – doesn’t fail if the cache file can’t be created
1.1 – removed a few more notices

53 Comments »

  1. Antony says:

    Very nice system. Thanks.

  2. Max says:

    Thanks!!!!!
    …better than phpThumb in my opinion.

  3. B00Mer says:

    Thanks!!!!
    Great script.. works great!!! #1

Leave a Reply

Friend Photomosaics


Turn your Facebook profile picture into a photomosaic made up of your friends profile pictures.

Details »

PHP Chart Class

Create line or bar charts and graphs within php. They can be output directly or image files created.

Details »

Drawing Gallery

Create your own drawing

Details »

Create Flash Drawing

A collection of many spontaneous drawings generated with Flash

Over a thousand random drawings created since 2003.

Details »

Font List


Details »

PHP Thumbnail Script

A script for converting images to different sizes inline, with support for server caching.

Details »

Flash Chess

Chess program designed to learn from player interaction. Made with flash and PHP server technology, the finished version will (in theory) be able to beat all players that aren’t as good as players that have played the system often.

Details »

PHP Font Writer


PHP font writer. uses GD and FreeType libraries to generate typefaces from truetype fonts.

Details »