2014-05-05 26 views
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'); 
    } 
+0

请确保您拥有'$ gallery_path的写入权限。 '/ thumbs''和'$ gallery_path。 '/ vierkant''和其他文件夹 – Guns

+0

权限是777,它适用于gd2 lib,但不适用于ImageMagick – user2696666

回答

1

替换这些行:

$配置[ 'source_image'] = SITE_URL()'凸纹资源/前/ IMG/M24CPP_x200/SBase1.jpg “; $ config ['new_image'] = site_url()。'marcella-resources/front/test/SBase1_copy.jpg'; 包含以下行:

$ config ['source_image'] ='marcella-resources/front/img/M24CPP_x200/SBase1.jpg'; $ config ['new_image'] ='marcella-resources/front/test/SBase1_copy.jpg';