CodeIgniter Forums
Simple Resize Model Setup - Printable Version

+- CodeIgniter Forums (
+-- Forum: General (
+--- Forum: Lounge (
+--- Thread: Simple Resize Model Setup (/thread-958.html)

Simple Resize Model Setup - wolfgang1983 - 02-01-2015

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;