![]() |
On-the-fly thumbnail generator - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: On-the-fly thumbnail generator (/showthread.php?tid=45900) |
On-the-fly thumbnail generator - El Forum - 10-10-2011 [eluser]Unknown[/eluser] Hi everyone, This is my first post and first contribution to the CodeIgniter community. I am working with CodeIgniter and Smarty (With Dwayne Charrington's library). Recently I used a Smarty Library that creates thumbnails for images "On the fly", and I found the idea really good, but not well integrated with CodeIgniter. I looked for CodeIgniter solutions, but didn't find my Graal. So here comes the solution I created (attachment), composed of 3 parts: 1. A Resize class inside library. This is a class I found on the Internet and modified a bit to fit my needs, I didn't used CodeIgniter library for various reasons: 1.1 There is no "Resize then Crop" feature. 1.2 Implementing such a feature would mean writing the file 2 times to disk. 1.3 I wanted to add Gray-scale conversions feature. 2. A thumbnail configuration file. 3. A thumbnail helper, which it the file you will load and use. 3b. A thumbnail Smarty function, that you can use if you are working with Dwayne Charrington's library Here is an example in how to use the helper (I assume it is already loaded): Code: <img src="<?=thumbnail('images/background.jpg', 400, 300)?>" alt="Background Thumbnail" /> Code: <img src="{thumbnail src='images/background.jpg' width=400 height=300}" alt="Background Thumbnail" /> Each one can take 2 optional arguments: option, can be : crop: The image will be resize then cropped to fill the exact requested size. exact: The image will be resize to the exact requested size. landscape: The image will be resize to fit the width, and height will be calculated to keep the same ratio. portrait: The image will be resize to fit the height, and width will be calculated to keep the same ratio. auto: The image will be resize, keeping the ration, and never being larger then the requested size. grayscale, if set to true, thumbnail will be converted to gray-scale. And here is the configuration file, as you can see, it is pretty flexible on where to save resized pictures : Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 1. Supports JPG, GIF and PNGs. 2. Resized images are generated only one time 3. If the original file is modified, is automatically refreshed. 4. Transparency is not lost. Installation: 1. Copy all files from the zip to you "application" folder, merge folders. 2. Modify thumnbail.php inside config folder to fit you needs. 3. Add the helper function anywhere you need a thumbnail. Hope you will find this useful, any request, remark or improvements are welcome ! On-the-fly thumbnail generator - El Forum - 05-27-2012 [eluser]cmarfil[/eluser] Hello, The link is broke, can you upload again? Thanks ![]() On-the-fly thumbnail generator - El Forum - 05-28-2012 [eluser]Unknown[/eluser] same here, please reupload ! Cheers |