resize image 950*950 in codeigniter

孤街浪徒 提交于 2019-12-13 02:59:56

问题


I hesitated on posting this question cause I saw dozens of them here, but all the answers didn't work.

So, I have this working code. It uploads picture and getting thumbnails.

I allow users to upload a 950*950 pictures. I want to resize those pics to fit in my show page.

So, here is part of the resize:

    $id=uniqid();

            $folder = $this->getDir($id);

            $dir=FCPATH.'upload/biz_photos/'.$folder.'/';

            if(!is_dir($dir)) {

              mkdirs($dir);
    }

    //handle img
    $des_file=$dir.$id.'.jpg';

            $thumb_file=$dir.$id.'.thumb.jpg';

            $info=getimagesize($org_file);

            if($info[0] <= 300) {

            copy($org_file,$dir.$id.'.jpg');

            }

            else

            {

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

            $config['image_library'] = 'GD2';

    $config['source_image']=$org_file;

    $config['new_image'] = $des_file;

        $config['overwrite']= true;

            $config['maintain_ratio'] =true;

            $config['width'] = 600;

            $config['height'] = floor(($info[1]/$info[0])*600);

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

        $this->image_lib->resize();

            // handle if there is any problem

            if ( ! $this->image_lib->resize()){

              echo $this->image_lib->display_errors();

            }

    }

Like when I test it, and upload a 950*950, and then check the uploaded image, the size still the original one. No resizing


回答1:


This image resize class is easy to set up and use https://github.com/Nimrod007/PHP_image_resize




回答2:


I did find the problem after few hours. So, I have a thumbnail function and I was passing to it the original picture instead of passing it the new picture (the sized picture).

Thanks




回答3:


$this->load->library('image_lib');
$config['source_image']=$org_file;
$config['new_image'] = $des_file;
$config['overwrite']= true;
$config['maintain_ratio'] =true;
$config['width'] = 950;
$config['height'] = 950;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();


来源:https://stackoverflow.com/questions/22210781/resize-image-950950-in-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!