PHP Classes

File: codeigniter/image_helper.php

Recommend this page to a friend!
  Classes of Kabir Hossain   PHP CodeIgniter Tips Tricks   codeigniter/image_helper.php   Download  
File: codeigniter/image_helper.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP CodeIgniter Tips Tricks
Collection of tips and examples to use CodeIgniter
Author: By
Last change:
Date: 16 days ago
Size: 1,281 bytes
 

Contents

Class file image Download
<?php
// SOURCE URL
// http://jrtashjian.com/2009/02/image-thumbnail-creation-caching-with-codeigniter/

function image_thumb($image_path, $height, $width)
{
   
// Get the CodeIgniter super object
   
$CI =& get_instance();

   
// Path to image thumbnail
    // Maybe we should get image name, image extension for right extension and $rawname . '_' . $height . '_' . $withd . '.jpg';
   
$image_thumb = dirname($image_path) . '/' . $height . '_' . $width . '.jpg';

    if( !
file_exists($image_thumb))
    {
       
// LOAD LIBRARY
       
$CI->load->library('image_lib');

       
// CONFIGURE IMAGE LIBRARY
       
$config['image_library'] = 'gd2';
       
$config['source_image'] = $image_path;
       
$config['new_image'] = $image_thumb;
       
$config['maintain_ratio'] = TRUE;
       
$config['height'] = $height;
       
$config['width'] = $width;
       
$CI->image_lib->initialize($config);
       
$CI->image_lib->resize();
       
$CI->image_lib->clear();
    }

    return
'<img src="' . dirname($_SERVER['SCRIPT_NAME']) . '/' . $image_thumb . '" />';
}
// USAGE
/* echo image_thumb('assets/images/picture-1/picture-1.jpg', 50, 50); */

/* End of file image_helper.php */
/* Location: ./application/helpers/image_helper.php */