简体   繁体   中英

Codeigniter resize and crop image

I need to resize image to fit 64x64 thumbnail. What I'm doing? I set resize width and height to 64px. If I set $config['maintain_ratio'] = false, image lose proportions. What I did: I set $config['maintain_ratio'] = TRUE; and $config['master_dim'] = 'width'; Now width is always 64px, but height is larger. I have somehow to crop image height to 64px from bottom. How can I achieve this? I tried to set up crop function, but I failed. Maybe there is another solution... My resize function

private function resize($up_data) {
        $config['image_library']  = 'gd2';
        $config['source_image']   = $up_data['full_path'];   
        $config['new_image']      = './images/autoriaithumb/';
        $config['create_thumb']   = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['thumb_marker'] = '_thumb';
        $config['width']          = 64;
        $config['height']         = 64;
        $config['quality']        = 100;
        $config['master_dim'] = 'width';

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

        $this->image_lib->resize();

}

try this

define 'upload config' as $image_config and define your crop config....as $config

$this->load->library('upload', $image_config);
if ($this->upload->do_upload()) {
  $this->load->library('image_lib',$config); 
  $this->image_lib->resize();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM