How to change the size of images in a template automatically

15 December 2017 | 39 views | Tags: Documentation

Tuskfish has an automatic image scaling and caching system that makes repurposing images a breeze. When you upload a nice master image with your content you often want to display it at smaller sizes in different contexts. Tuskfish can generate thumbnails to suit the needs of your templates automatically. Rather than accessing the image property of a content item directly, call the function getCachedImage() in a template, passing in the desired width as an argument, for example:

<img src="<?php echo $content->getCachedImage(500); ?>" alt="<?php echo $content->escape('caption'); ?>"/>

Tuskfish will use the master image you uploaded with the content item to create a thumbnail 500 pixels wide and save it in the cache. The next time this template is called in a page load Tuskfish will check the cache to see if the thumbnail already exists, and since it does, your site will save CPU load and bandwidth.

If you later decided that 500 pixels was too big, and wanted to reduce the size of the images in a given template to 150 pixels wide, you would just change the argument to 150 in the template code. Tuskfish will then build and cache thumbnails at the new size for you automatically, as pages are requested. You don't need to do anything, it will "just happen". Cool, huh?

For best results please ensure your images have been converted to the sRGB colour space, as PHP's GD library is not colour space aware.

Copyright, all rights reserved.

Related

Tuskfish CMS User Manual

The user manual provides a comprehensive guide to Tuskfish CMS operations. It covers all all aspects from installation to adding and curating content, managing site security and customisation of themes. For additional information on how to customise Tuskfish please see the developer guide.