phpcodeigniteractiverecordimage-processingimagelibrary

Resize image without distortion of image in codeigniter


I want to resize image without image being distorted.For example if i have set the image height to be 100 and width as 200.The image resized must be of 100 height and 200 width.In order to achieve that i want to crop that image instead of getting it distorted.

My config options:-

            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = FALSE;
            $config['master_dim'] = 'auto';
            $config['width'] = 100;
            $config['height']= 100;

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

Also is it possible without using any other library of image manipulation?


Solution

  • I have solved my problem. I had to re-sized my image and then crop it. Its a bit of long process anyways if you have a better than this please suggest.

    My code:

                //Resize Image
                $config = array();
                $config['image_library'] = 'gd2';
                $config['source_image'] = './assets/original/'.$image_name;
                $config['new_image'] = './assets/banner/'.$image_name;
                $config['create_thumb'] = FALSE;
                $config['maintain_ratio'] = TRUE;
                $config['master_dim']= 'width';
                $config['quality']  = '100';
                $config['width'] = 1260;
                $config['height']= 645;
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
                // Crop Image
                $config = array();
                $config['image_library'] = 'gd2';
                $config['source_image'] = './assets/banner/'.$image_name;
                $config['new_image'] = './assets/banner/'.$image_name;
                $config['create_thumb'] = FALSE;
                $config['maintain_ratio'] = FALSE;
                $config['quality']  = '100';
                $config['x_axis'] = 0;
                $config['y_axis'] = 0;
                $config['width'] = 1260;
                $config['height']= 645;
                $this->image_lib->initialize($config);
                $this->image_lib->crop();