【问题标题】:codeigniter: how to resize after croppingcodeigniter:裁剪后如何调整大小
【发布时间】:2011-10-14 00:17:07
【问题描述】:

所以我正在使用以下代码(成功)裁剪我上传的图像:

    $file_name = $this->input->post('file_name');
    $x1 = $this->input->post('x1');
    $y1 = $this->input->post('y1');
    $x2 = $this->input->post('x2');
    $y2 = $this->input->post('y2');

    //die('width: '.$width.' height: '.$height.' id: '.$id.' file_name: '.$file_name.' x1: '.$x1.' x2: '.$x2.' y1: '.$y1.' y2: '.$y2.' w: '.$w.' h: '.$h);

    $config['image_library'] = 'gd2';
    $config['source_image']    = './images/uploads/temp/'.$file_name;
    $config['maintain_ratio'] = FALSE;
    $config['width'] = $y2;
    $config['height'] = $y2;
    $config['x_axis'] = $x1;
    $config['y_axis'] = $y1;
    $this->image_lib->initialize($config); 

此时我想调整图像的大小,因为我刚刚获得了我想要的选择和比例,但不知道该怎么做。以下是我认为随后会以同样的方法立即起作用的方法:

    $config['width'] = 180;
    $config['height'] = 180;
    $this->load->library('image_lib', $config); 
    $this->image_lib->resize();

    if ( ! $this->image_lib->resize() )
    {
        die( $this->image_lib->display_errors() ); //
    } 

它不会给出任何错误或任何东西,它只是不会调整图像大小。你能帮我弄清楚发生了什么吗?

【问题讨论】:

    标签: php codeigniter image-processing


    【解决方案1】:

    就好像您第二次加载库(从而再次对其进行初始化)时,它没有收到它需要的所有参数。您是在相同的方法中使用代码,还是在其他方法中使用代码? 无论如何,如果在同一个方法中,作为测试在清除它们后尝试加倍一些配置:

    //
    //CROPPING HERE....Then:
    //
    
    $this->image_lib->clear();
    
    $config['image_library'] = 'gd2';
    $config['source_image']    = './images/uploads/temp/'.$file_name;
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 180;
    $config['height'] = 180;
    
    $this->image_lib->initialize($config);
    
    if ( ! $this->image_lib->resize())
    {
        echo $this->image_lib->display_errors();
    }
    

    并确保文件夹和文件具有正确的权限。

    【讨论】:

    • 成功了!!!!!!你是我的英雄!裁剪有点偏离,但我可以摆弄。
    猜你喜欢
    • 2011-06-14
    • 1970-01-01
    • 2012-11-10
    • 2013-03-01
    • 2010-10-10
    • 2014-01-11
    • 2010-10-03
    相关资源
    最近更新 更多