上传时调整大小时出错

时间:2012-01-03 09:55:39

标签: php codeigniter image-uploading image-resizing

我必须将图片上传到上传文件夹。上传文件如下

$profile_image    = 'profile_image';
$this->load->library('custom_upload_lib');
//get file extension
$fileExtension = "";
if($_FILES["profile_image"]["name"]):
    // "profile_image" is the form input field name
    $path_info = pathinfo($_FILES["profile_image"]["name"]); 
    $fileExtension    = $path_info['extension'];
endif;
$upload_path      = './uploads/profile_image/';
$allowed_types    = 'GIF|gif|PNG|png|jpg|JPEG|jpeg';
$max_size         = 2048;
$encrypt          = false;
$saved_file_name  = "profile_".rand(2,8)
                    .strtotime(date('Y-m-d H:i:s')).'.'.$fileExtension;
//$saved_file_name=$_FILES["profile_image"]["name"];
$overwrite        = false;
$upload_control_name = $profile_image ;
$filePath            = "";
$uploadname          = "";
if($fileExtension != "") 
{
    $upload_data =  $this->custom_upload_lib->configure_upload($upload_path,
        $allowed_types,$max_size,$encrypt,$saved_file_name,
        $overwrite,$upload_control_name);
    if(is_array($upload_data)) 
    {
        $filePath         = $upload_data['full_path'];
        $uploadname       = 'profile_image/'.$upload_data['file_name'];
        $temp_upload_name = $upload_data['file_name'];

        $width  = 90;
        $height = 90;
        $this->load->library('resize_lib');
        $resize   = $this->resize_lib->_resizeImage( 
                        $filePath ,$temp_upload_name, $width, $height);

        if(!$resize) 
        {
            $message   = $resize;
            $this->session->set_flashdata('message', $message );
            redirect(site_url('admin/preacher'));
        }
    }
    else 
    {
        $message   =  $upload_data;
        $this->session->set_flashdata('message', $message );
        redirect(site_url('admin/preacher'));
    }
}

我必须将图像大小调整为90 X 90.但是调整大小不起作用..

1 个答案:

答案 0 :(得分:1)

您必须使用image_lib。使用以下代码调整图片大小

$config['image_library'] = 'gd2';
$config['source_image'] = $upload_path.$saved_file_name;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width']     = 90;
$config['height']   = 90;

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

$this->image_lib->resize();