• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Simple Resize Model Setup

#1
Another quick little code came up with if any one wants to use.

If you would like to resize images with out having to put a resize function in each controller each time, you could use this model and then in your controller

All you would have to enter is $this->image_resize->resize('1.jpg', 100, 100); the first one is image name, the second part is image width size and third is image height. make sure load model of course in controller.

PHP Code:
<?php 

class Image_resize extends CI_Model {
    
    public function 
resize($filename$width$height) {
        
$config['image_library'] = 'gd2';
        
$config['source_image'] = FCPATH 'upload'.'/'.$filename;
        
$config['create_thumb'] = FALSE;
        
$config['maintain_ratio'] = FALSE;
        
$config['width'] = $width;
        
$config['height'] = $height;
        
$config['new_image'] = FCPATH 'image/cache'.'/'.$width.'x'.$height.'-'.$filename;

        
$this->load->library('image_lib'$config);
        
$this->image_lib->initialize($config); 

        
$this->image_lib->resize();
    }




Attached Files
.php   image_resize.php (Size: 562 bytes / Downloads: 169)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.