HowTo: Create Picture Thumbnails with PHP and GD
Hi, first of all I’d like to wish you all a Happy New Year. Hope you enjoyed your holidays, because I know most of us are now behind the desks again, working.
Now, here’s a nice PHP plugin you can use to generate thumbnails in PHP. It’s called phpThumb and you can get it from phpthumb.sourceforge.net.
First of all take note that this plugin uses the GD or ImageMagick library so be sure you have at least one of them installed on your server/host. I’m using GD and it works just fine. ImageMagick has some extra features that I didn’t need, so be sure to check the official site for more details.
How To use phpThumb:
Copy the contents of the plugin somwhere in your site’s directory ( eg. /lib/phpThumb/ )
Rename the phpThumb.config.php.default to phpThumb.config.php. I didn’t modify this config at all but you might take a look inside it if you’d like to setup various parameters.
Having that done you can easily generate thumbnails like this:
<img src=”lib/phpthumb/phpThumb.php?src=nameofthefile.jpg&w=150&h=50&zc=1″ alt =”someText” />
w stands for width of course and h stands for height. zc means zoomCrop.
The plugin has a lot of other options and tweaks to play with, check’em out here.
Enjoy

Leave a Reply