0
我有一個可以上傳圖片的控制器。現在gd2庫的作品完美,除了大圖片。所以我想爲此使用ImageMagick。但我無法得到它的工作。我使用mamp作爲我的本地主機。如何在codeigniter中使用ImageMagick
這是我的代碼:
function voegfotostoe()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
$datap = array('upload_data' => $this->upload->data());
$id = $this->input->post('id');
$gallery_path = realpath(APPPATH . '/../uploads');
$upload_data = $this->upload->data();
$this->load->library('image_lib');
/* Size 350px x 300px */
$config['image_library'] = 'ImageMagick';
$config['library_path'] = '/usr/bin/';
$config['source_image'] = $upload_data['full_path'];
$config['new_image'] = $gallery_path . '/thumbs';
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 350;
$config['height'] = 300;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->upload->display_errors();
$this->image_lib->resize();
$config['image_library'] = 'ImageMagick';
$config['library_path'] = '/usr/bin/';
$config['source_image'] = $upload_data['file_path'] . 'thumbs/' . $upload_data['orig_name'];
$config['new_image'] = $gallery_path . '/vierkant';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 200;
$config['height'] = 200;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->crop();
$thumb = $this->upload->data();
$thumbname = $thumb['raw_name'] . $thumb['file_ext'];
/* Size 600px X 600px */
$config['image_library'] = 'ImageMagick';
$config['library_path'] = '/usr/bin/';
$config['source_image'] = $upload_data['full_path'];
$config['new_image'] = $gallery_path . '/medium';
$config['thumb_marker'] = '_medium';
$config['maintain_ratio'] = TRUE;
$config['width'] = 500;
$config['height'] = 500;
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->resize();
$medium = $this->upload->data();
$mediumname = $medium['raw_name'] . '_medium'. $medium['file_ext'];
$data = array(
'fk_land' => $this->input->post('landid'),
'titel' => $this->input->post('titel'),
'period' => $this->input->post('period'),
'size' => $this->input->post('size'),
'info' => $this->input->post('info'),
'region' => $this->input->post('region'),
'cat_id' => $this->input->post('catsculp'),
'color' => $this->input->post('color'),
'order' => $this->input->post('landtoevoegen'),
'gallery_name' => $this->input->post('painter'),
'thumb_img' => $thumbname,
'medium_img' => $mediumname
);
if($datap['upload_data']['orig_name'] != "") $data['gallery_img'] = $datap['upload_data']['orig_name'];
$this->Cms_model->voegfototoe($data);
redirect('home#toevoegen','refresh');
}
請確保您擁有'$ gallery_path的寫入權限。 '/ thumbs''和'$ gallery_path。 '/ vierkant''和其他文件夾 – Guns
權限是777,它適用於gd2 lib,但不適用於ImageMagick – user2696666