WSN Links
Featuresspacer Showcasespacer Reviewsspacer Demosspacer Purchasespacer Manualspacer Support

Register | Forgot Password
Thumbnails
Thumbnails
By Paul

When a visitor uploads an image attachment, you may sometimes wish to show that image at a smaller size than it actually is. While HTML allows constricting the size in the img tag, this is a bad idea because the browser still has to download the full image, thus annoying modem users and wasting your bandwidth. The solution to this is thumbnails -- automatically generated miniature versions of the images.

Note that usage of thumbnails requires PHP's GD library, which is bundled with PHP 4.3.0+, or ImageMagick. Under settings->files in your admin panel you need to select your graphics method, either GD or ImageMagick.

The default templates already have code for displaying attachments in them, but for educational purposes we'll discuss how to show them anyhow. To use thumbnails in WSN Links for a link, unless you use {LINKTHUMBURL} you'll have to be within the attachments area for a link. When within the scope of a link you open and close attachments areas with <!-- BEGIN LINK ATTACHMENTS --> and <!-- END LINK ATTACHMENTS -->. Here's an example which shows thumbnails only for images (not other file types) and offers a link to the full size version:
<!-- BEGIN LINK ATTACHMENTS -->
<IF {ATTACHISIMAGE}> <a href="http://scripts.webmastersite.net/wsnlinks/wsnmanual410/{ATTACHDOWNLOADURL}"><img src="http://scripts.webmastersite.net/wsnlinks/wsnmanual410/{ATTACHTHUMBURL}" alt="image"></a> <br></IF>
<!-- END LINK ATTACHMENTS -->


That template code shows a thumbnail for all image attachments. {ATTACHTHUMBURL} is a shortened version which allows direct caching to work, you can also write it out as thumbnail.php?id={LINKID}&attachid={ATTACHID} . You can modify this basic code change some things such as the size of the thumbnail. For example, this sets the thumbnail size at 60x60:

<img src="http://scripts.webmastersite.net/wsnlinks/wsnmanual410/thumbnail.php?id={LINKID}&attachid={ATTACHID}&thumbwidth=60&thumbheight=60 ">


Change the thumbwidth and thumbheight values as you desire.

By default thumbnails retain the aspect ratio of the original image. Thus they will not come out to exactly the dimensions you specify (unless you specify that you want that in your file settings), they will use that as the upper boundry but will not distort the image to fill it.

You can set default thumbnails for various file types for which no actual thumbnail of the file can be rendered (for example, .doc or .mp3 files). To do this, save a file as extension.png in your templates/images_default directory (or templates/multilingual/images if using a multilingual install), where 'extension' is replaced by the extension of the file type you want this shown for. For example, you could save a thumbnail picture to be shown for all .mp3 files by creating an mp3.png file.

For thumbnails on a custom file field of a category or the like, see the custom file fields article.

Rating:


2.17/5 based on 6 votes. The median rating is 3.

Submitted: 12/07/03 (Edited 10/08/07)

Description: Generating thumbnails of attachments.

Views: 2131 views. Averaging 1 per day.
In the most recent 30 day period, there've been 1 views.

Previous Article | Next Article

Home    |    Features    |    Showcase    |    Reviews    |    Demos    |    Purchase    |    Manual    |    Support