2014-03-05 4 views
0

나는이 질문을 게시하는 것을 주저했다. 나는 그들 중 수십개를 보았으나 모든 대답은 작동하지 않았다.크기 조정 이미지 950 * 950 in codeigniter

그래서이 작업 코드가 있습니다. 사진을 업로드하고 미리보기 이미지를 가져옵니다.

사용자가 950 * 950 사진을 업로드 할 수 있도록 허용합니다. 내 사진 페이지에 맞게 사진 크기를 조정하고 싶습니다.

그래서, 여기에 크기 조정의 일부입니다

$id=uniqid(); 

      $folder = $this->getDir($id); 

      $dir=FCPATH.'upload/biz_photos/'.$folder.'/'; 

      if(!is_dir($dir)) { 

       mkdirs($dir); 
    } 

    //handle img 
    $des_file=$dir.$id.'.jpg'; 

      $thumb_file=$dir.$id.'.thumb.jpg'; 

      $info=getimagesize($org_file); 

      if($info[0] <= 300) { 

      copy($org_file,$dir.$id.'.jpg'); 

      } 

      else 

      { 

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

      $config['image_library'] = 'GD2'; 

    $config['source_image']=$org_file; 

    $config['new_image'] = $des_file; 

     $config['overwrite']= true; 

      $config['maintain_ratio'] =true; 

      $config['width'] = 600; 

      $config['height'] = floor(($info[1]/$info[0])*600); 

      $this->image_lib->initialize($config); 

     $this->image_lib->resize(); 

      // handle if there is any problem 

      if (! $this->image_lib->resize()){ 

       echo $this->image_lib->display_errors(); 

      } 

    } 

처럼 내가 업로드 한 이미지를 확인 한 후 테스트하고, 950 * 950을 업로드하고, 크기 여전히 원래 하나. 어떤 크기 조정

+0

가 있습니까? – Samutz

+0

몇 가지 메모 : 이미지 라이브러리는 덮어 쓰기 환경 설정을 사용하지 않습니다 (파일 업로드 라이브러리와 혼동 스러울 수도 있음). resize() 함수를 두 번 실행합니다 (처음에는 initialize()와 if 문에서 다시). 첫번째 것을 제거 할 수 있습니다. – Samutz

+0

@Samutz 예, 이미지 업로드 중입니다. 문제 없습니다. 이미지 라이브러리가 덮어 쓰기 환경 설정을 사용하지 않는다는 것에 대해 혼란스러워합니다. –

답변

0

쉽게 사용할 수 없습니다. 따라서 축소판 기능이 있고 새로운 그림 (크기가 지정된 그림)을 전달하는 대신 원본 그림을 전달했습니다. 이 프로그램을 실행할 때`$의 des_file`에 의해 지정된 파일/덮어 생성되는

감사

0

이 이미지 크기 조정 클래스를 설정하고 난 몇 시간 후 문제를 발견했다 https://github.com/Nimrod007/PHP_image_resize

+0

그런데 좋은 수업이지만, 나는 CI 방법을 유지하려고 노력하고있다. –

0
$this->load->library('image_lib'); 
$config['source_image']=$org_file; 
$config['new_image'] = $des_file; 
$config['overwrite']= true; 
$config['maintain_ratio'] =true; 
$config['width'] = 950; 
$config['height'] = 950; 
$this->image_lib->clear(); 
$this->image_lib->initialize($config); 
$this->image_lib->resize();