Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter图像大小调整不工作_Php_Codeigniter_Image Processing_Image Resizing - Fatal编程技术网

Php Codeigniter图像大小调整不工作

Php Codeigniter图像大小调整不工作,php,codeigniter,image-processing,image-resizing,Php,Codeigniter,Image Processing,Image Resizing,我试图将上传的图像调整到163px的高度,保持纵横比,然后将其上传到文件夹。我尝试了以下代码: $id=1; // user id $this->load->library('image_lib'); $filename=$_FILES['file']['name']; $config['image_library'] = 'gd2'; $config['upload_path'] = './userdata/'.$id; $config['height'] = '163px

我试图将上传的图像调整到163px的高度,保持纵横比,然后将其上传到文件夹。我尝试了以下代码:

$id=1;     // user id
$this->load->library('image_lib');
$filename=$_FILES['file']['name'];
$config['image_library'] = 'gd2';
$config['upload_path'] = './userdata/'.$id;
$config['height'] = '163px';
$config['maintain_ratio'] = TRUE;
//$config['master_dim'] = 'height';
$config['source_image'] = $filename;
$this->load->library('upload', $config);
$this->image_lib->initialize($config);
$this->image_lib->resize();
if(!$this->upload->do_upload('file')) 
{               
     echo $this->data['error'] = $this->upload->display_errors();
}
但是,这会将图像上载到正确的文件夹中,但不会调整图像的大小。我上传了一张大小为*170*128*的图片,它按原样上传到文件夹中,没有调整大小。我的代码有什么问题

有人能帮我找到问题吗


提前感谢。

试试这个更简洁的版本,高度或宽度的配置不需要px,因此您的代码有点混乱:

$id = 1;

$config = array(
    'upload_path'   => './userdata/'.$id,
    'allowed_types' => 'gif|jpg|jpeg|png',
    'encrypt_name'  => true,
);

$this->load->library('upload', $config);

$field_name = "file"; // change this with your file upload part's field name if different

if ($this->upload->do_upload($field_name)) {
    $image = $this->upload->data();
    $config = array(
        'image_library'   => 'gd2',
        'source_image' => $image['full_path'],
        'maintain_ratio'  => true,
        'height'  => 163,
     );
     $this->load->library('image_lib', $config);
     if (!$this->image_lib->resize()) {
            echo $this->image_lib->display_errors();
     }
     $this->image_lib->clear();
}

高度是否需要以px为单位?或者你可以只使用'163'?它应该是
$config['height']='163'
remove
px
我已经在我的本地和它的工作中尝试过了,你能检查一下gd是否通过一个简单的phpinfo()调用安装或启用了吗?@Burak..我让它工作了。问题是我多次包含
$this->load->library('image_lib')
。很高兴听到你修复了这个问题。