i have a controller wich can upload images. Now gd2 library works perfectly except for big images. So i want to use ImageMagick for this. But i can't get it working. I use mamp for my localhost.
This is my code:
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');
}
Replace these lines:
$config['source_image'] = site_url().'marcella-resources/front/img/M24CPP_x200/SBase1.jpg'; $config['new_image'] = site_url().'marcella-resources/front/test/SBase1_copy.jpg';
with these lines:
$config['source_image'] = 'marcella-resources/front/img/M24CPP_x200/SBase1.jpg'; $config['new_image'] = 'marcella-resources/front/test/SBase1_copy.jpg';