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

Leave a Reply

Isometric Projection with JavaScript in HTML5 vs Flash and Actionscript

Recently I decided to build part of a game that used an isometric projection for displaying the game board using HTML5.
Dirty plagiarist that I am, I found an excellent (albeit very old) tutorial by Danko Kozar for doing this. However it was written in Actionscript. No bother – I just modified the code to work in HTML5. This meant I could more or less ignore the theory of how isometric projection works and just get down to the business of doing it. Porting the code was easy. As it says in the tutorial:

These tutorials can be used for programming an isometric game in many programming languages not just in Flash. They are more about game programming than about Flash programming.

Here’s the swf from Danko’s tutorial:
Details »

Dynamic Leaderboard

So you want to create a dynamic leaderboard that changes on the fly using jQuery? Well do ya?

Here’s the scenario: you have some cool (to you at least) data that you want to put up on a webpage/kiosk/touchscreen/smartphone that animates beautifully in real time to update the results.

Here’s an example of what I’m talking about:


    Details »

    Handy Linux Shortcuts and How To’s

    Here’s some linux tricks I use in my line of work. I find them useful, you may not. You decide.
    Details »

    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 »