The process of outputting a series of thumbnail images to the browser occurs in two steps. First, you create a script that outputs an image; then you use this script file as the source for an img tag.
The code in Listing 6-7 shows the script file for outputting an image. It retrieves the path and size from a query string and uses these values to construct a thumbnail and then display it (in this chapter's downloads, this is the file getthumb.php).
<?php //this file will be the src for an img tag require 'ThumbnailImage.php'; $path = $_GET["path"]; $maxsize = @$_GET["size"]; if(!isset($maxsize)){ $maxsize = 100; } if(isset($path)){ $thumb = new ThumbNailImage($path, $maxsize); ❶$thumb->getImage(); } ?> |
When passed a query string describing the path to an image file and the desired image size, this code outputs a thumbnail directly to the browser. The getImage method (❶) tells the browser the MIME type to expect and then sends the image file in binary format.
Note:
Typing getthumb.php?path=graphics/filename.jpg into the browser address bar is equivalent to pointing your browser directly at an image file. However, because you want to output a series of pictures and control their position, you will use this file as the src attribute of an img tag.
18.191.46.36