Create thumbnail images in CodeIgniter

In this post i would like to explain about how to create thumbnail images in codeigniter framework. In the following function will give the clear understand about the code.

Create thumbnail images in CodeIgniter by Anil Kumar Panigrahi

Create thumbnail images in CodeIgniter by Anil Kumar Panigrahi

Create Thumbnail Function

function _createThumbnail($fileName) {
$config['image_library'] = 'gd2';
$config['source_image'] = 'uploads/' . $fileName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 75;

$this->load->library('image_lib', $config);
if(!$this->image_lib->resize()) echo $this->image_lib->display_errors();
}

Call the above function like :

$this->_createThumbnail($fInfo['file_name']);

After creation of thumbnail clear the caches.

$this->image_lib->clear();

Hope that it will be useful.

Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

5 Responses

  1. Israel says:

    Hello, your function needs to know where to save the thumbnail.
    $config[‘new_image’] = ‘./thumbs_folder/’ . $fileName;

    Thank you!

  2. GP Code library
    Create thumbnail image by php
    When we upload large size images on server. Uploaded large images take more time to load on webpage, so we need to show small size images on our webpage. Image thumbnail is a solution to generate uploaded image’s thumbnail to show required size images on our website.
    http://codelibrary.googleplus.co.in/create-thumbnail-image-by-php/

  3. tushar says:

    Hey dude,
    codeigniter by default resize the image with aspect ratio..
    Example:

    if I resize an image of 760 x 540 and gives height = width = 80 to resize function it generates thumbnail of 80 x 61 !!!!!

    any suggestion or this???

  4. hira says:

    can we use this method to create thumbnail /screenshort s of webpages?
    like passing url in $file_path?
    as I need to display the thumbnails of different websites,
    thanks in advance

  1. January 22, 2010

    […] Read the rest here: Create thumbnail images in codeIgniter « ANIL KUMAR PANIGRAHI 's Blog […]

Leave a Reply

Your email address will not be published. Required fields are marked *