CodeIgniter Forums

Full Version: Simple Resize Model Setup
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:

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;