Thumbnails are found on alot of website accross the web. They are used to save bandwidth and increase page load time. Add images that were once too big for your website into your website with ease. No need to create two copies of the same image, just let PHP do it for you. Not only is it automated, it will even recreate a thumb with a different file size from an extrenal image which will reduce alot of used bandwidth, not just make the height and width different!
Lets start off with a new file called
thumb.php. Add your php tags around the file and lets add in the following synthax
CODE
// Get image info from variable
$url = $_GET['url'];
$img = getimagesize($url) or die();
This is the base of our script. Without this, the enter script would not work properly. What this does is setup a variable named
url and holds the value of the url of which the image originates that will be nailed. The image function
getimagefromsize() will simply get certain information about an image. It will return a variable in an array with four elements. We will be using three of the four elements.
- 0 - Produces the width of an image in pixels
- 1 - Produces the height of an image in pixels
- 2 - Produces the flag indicating the type of image
More information on this function can be found here:
http://www.php.net/getimagesize