CodeIgniter图像裁剪 - 不受crop()参数影响的图像

pep*_*epe 1 php gd codeigniter crop image-processing

我有这个模型来裁剪用户的图像

function crop_avatar()
{
    $id = $this->tank_auth->get_user_id();

    //get current avatar
    $query = $this->db->get_where('user_profiles', array('id' => $id));
    foreach ($query->result() as $row) {
        $j[$row->avatar] = $row->avatar;
    }

    $config['image_library'] = 'gd';
    $config['source_image'] = '.' . substr("$row->avatar", 18);
    $config['x_axis'] = '10';
    $config['y_axis'] = '60';
    $this->load->library('image_lib');      
    $this->image_lib->initialize($config); 

    if ( ! $this->image_lib->crop())
    {
        echo $this->image_lib->display_errors();
    }

//      print_r($config);


}
Run Code Online (Sandbox Code Playgroud)

生成这个数组(通过print_r)

Array
(
    [image_library] => gd
    [source_image] => ./images/avatars/b0b623057.jpg
    [x_axis] => 10
    [y_axis] => 60
)
Run Code Online (Sandbox Code Playgroud)

由于某种原因我不知道 - 没有任何裁剪.原始图像通过此模型直接传递,并且不变.

我的服务器上有GD - 任何想法在这里可能有什么问题?

万分感谢.

jfo*_*her 7

您需要定义要裁剪图像的宽度和高度.

x_axisy_axis配置值是在现有的图像,其中作物应该启动点.

换句话说,你需要4个测量来裁剪图像:垂直开始的地方(y_axis),水平开始的地方(x_axis),垂直结束的地方(height)和水平结束的地方(width)

如果裁剪图像的某个尺寸与原始图像的尺寸相同,请不要忘记设置maintain_ratiofalse