2010-08-23 3 views
1

나는 jcrop과 codeigniter를 사용하여 사용자가 업로드 한 이미지를 잘라내 기 위해 이미지를 90x60 크기로 자르고 싶지만 아무 것도 시도하지 않은 것은 현재 보이는 코드가 보인다. 이 같은image codeigniter로 자르기

CONTROLLER

function save_crop() { 
     $this->load->library('image_lib'); 

     $config['image_library'] = 'gd2'; 
     //$config['library_path'] = '/usr/X11R6/bin/'; 
     $config['source_image'] = './media/images/uploads/company_uploads/' . $this->input->post('image_name'); 
     //$config['new_image'] = './media/images/uploads/company_uploads/cropped' . $this->input->post('image_name').'_'.time(); 
     //die($config['source_image']); 
     $config['x_axis'] = $this->input->post('x'); 
     $config['y_axis'] = $this->input->post('y'); 
     $config['width'] = $this->input->post('w'); 
     $config['height'] = $this->input->post('h'); 
     $config['maintain_ration'] = TRUE; 
     $config['dynamic_output'] = TRUE; 
     $this->image_lib->initialize($config); 

     if(!$this->image_lib->crop()) { 
      echo $this->image_lib->display_errors(); 
     } else { 
      echo "Success"; 
     } 
    } 

JAVASCRIPT

$('#jcrop_target').Jcrop({ 
     onChange: showPreview, 
     onSelect: showCoords, 
     aspectRatio: 1, 
     addClass: 'custom', 
     maxSize: [90,60] 
    }); 

    function showPreview(coords) 
    { 
     var rx = 100/coords.w; 
     var ry = 100/coords.h; 

     $('#preview').css({ 
      width: Math.round(rx * 500) + 'px', 
      height: Math.round(ry * 370) + 'px', 
      marginLeft: '-' + Math.round(rx * coords.x) + 'px', 
      marginTop: '-' + Math.round(ry * coords.y) + 'px' 
     }); 
    }; 

    function showCoords(c) 
    { 
     $('#x').val(c.x); 
     $('#y').val(c.y); 
     $('#x2').val(c.x2); 
     $('#y2').val(c.y2); 
     $('#w').val(c.w); 
     $('#h').val(c.h); 
    }; 

HTML

<?php if(isset($upload_data)) :?> 
      <?php if($upload_data['image_width'] > 90 || $upload_data['image_height'] > 60) : ?> 
      <p>Your image is a little large</p> 
      <form action="<?php echo base_url();?>employer/save_crop" method="post"> 
      <div id="uploaded_image"> 
       <img src="<?php echo base_url();?>media/images/uploads/company_uploads/<?php echo $upload_data['file_name'];?>" id="jcrop_target"/> 
      </div> 
       <div id="uploaded_preview"> 
       <img src="<?php echo base_url();?>media/images/uploads/company_uploads/<?php echo $upload_data['file_name'];?>" id="preview"/> 
       </div> 
       <input type="hidden" name="x" id="x" /> 
       <input type="hidden" name="y" id="y" /> 
       <input type="hidden" name="x2" id="x2" /> 
       <input type="hidden" name="y2" id="y2" /> 
       <input type="text" name="w" id="w" /> 
       <input type="text" name="h" id="h" /> 
       <input type="hidden" name="image_name" value="<?php echo $upload_data['file_name'];?>"/> 
       <input type="submit" name="crop_image" value="Crop" /> 
      </form> 
      <?php endif; ?> 
     <?php endif; ?> 

답변

0

당신이 CodeIgniter를 던지고되었다는 오류 메시지 (들)을 게시하는 경우, 그것은 우리가 더 많은 도움이 될 수있다.

유효성 검사에 Codeigniter의 'Form helper'를 활용하고 있습니까? '이 maxSize가'jCrop에 올바르게 설정되어있는 경우, 당신은 어떤 문제가 필요하지 말아야 ...

오류 당신은 maintain_ration 대신 maintain_ratio를 삽입해야합니다

1
$config['maintain_ratio'] = TRUE; 

을 :)하시기 바랍니다.