2011-10-03 158 views
0

我试过下面的代码在codeigniter中裁剪图像,但它没有工作。可能是我错过了分钟的事情。助手已加载,并且图像也存在 的代码是Codeigniter图像不裁剪

public function cropAndSave(){ 
        $config['image_library'] = 'gd2'; 
        $config['allowed_types'] = 'gif|jpg|png'; 
        $config['source_image'] = './img-lab/xxx.jpg'; 
        $config['create_thumb'] = true; 
        $config['maintain_ratio'] = false; 
        $config['width'] = 150; 
        $config['height'] = 190; 
        $config['new_image'] = "thumb_shahid.jpg"; 
        $this->load->library('image_lib', $config); 
        $this->image_lib->resize(); 
        echo ' 
        <script> 
         window.parent.location="'. base_url().'" 
        </script> 
        '; 
} 
+0

无论错误显示 –

+0

的某些其它代码/上下文会有帮助。例如,你在做什么!$ this-> image_lib-> crop()检查?我也想象一下,mypic.jpg不会是你图片的完整路径。 – simnom

+0

您是否启用了完整的日志记录/调试功能?你还使用什么图形库?它没有被定义为'gd2'?等等;你需要安装该模块才能使用它,帮助者只是'帮助'使它更容易做到。 – Jakub

回答

1

调用initialize()功能,而不是load()因为你的图像库已经加载

public function cropAndSave(){ 
         $config['image_library'] = 'gd2'; 
         $config['allowed_types'] = 'gif|jpg|png'; 
         $config['source_image'] = './img-lab/xxx.jpg'; 
         $config['create_thumb'] = true; 
         $config['maintain_ratio'] = false; 
         $config['width'] = 150; 
         $config['height'] = 190; 
         $config['new_image'] = "thumb_shahid.jpg"; 
         $this->image_lib->initialize($config); 
         $this->image_lib->resize(); 
         echo ' 
         <script> 
          window.parent.location="'. base_url().'" 
         </script> 
         '; 
    } 
+0

太棒了!有效。谢谢 –