Welcome Guest, Not a member yet? Register   Sign In
Simple Resize Model Function
#1

(This post was last modified: 10-08-2015, 04:15 PM by wolfgang1983.)

Hi All,

I know people like to make there on code. But though would share my image_lib resize function

You will need to create a image folder in main directory. And also inside that image directory create a subfolder you could name it new_image folder or rename it to what you would like just remember to change it on model.


PHP Code:
<?php

class Model_image extends CI_Model {

    public function 
resize($filename$width$height) {

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

        
$config['image_library'] = 'gd2';
         
$config['source_image'] = FCPATH 'image/' $filename;
        
$config['new_image'] = FCPATH 'image/cache/' $filename;
        
$config['create_thumb'] = FALSE;
        
$config['maintain_ratio'] = FALSE;
        
$config['width'] = $width;
        
$config['height'] = $height;

        
$this->image_lib->initialize($config); 

        
$this->image_lib->resize();

        if (
file_exists(FCPATH 'image/cache/'$filename)) {
            return 
base_url('image/cache/'$filename);
        }
    }



Load the model on to a controller where need.



PHP Code:
$this->load->model('model_image');

$image 'my_image.png';

$this->model_image->resize($image100100); 
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB