This code is for a stand-alone file, named "thumbnail.php" or something similar. Once uploaded to your server, it can be called from inside an IMG tag.
There are four options for this script without modifying anything.
- First, you can resize the image to a percentage of the original, as to maintain aspect ratio.
- Second, you can set a maximum width for the thumbnails.
- Third, you can set a maximum height for the thumbnails.
- Lastly, if you do not specify a way to create the thumbnail, then the script defaults to creating a thumbnail 25% of the size of the original preserving its original aspect ratio.
So, when you need the thumbnail, you can call it like these examples, depending on what you need:
// This creates a thumbnail 30% size of the original
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&pct=30">
// This creates a thumbnail with a maximum width of 150 pixels
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&maxw=150">
// This creates a thumbnail with a maximum height of 100 pixels.
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg&maxh=100">
// The default creates a thumbnail 25% of it's original size preserving its original aspect ratio
<img src="http://www.mysite.com/theabovecode.php?filename=images/yourimage.jpg">
I hope this helps someone out there looking for a Quick 'n Dirty thumbnail script.