2017-10-11 145 views
-3

如何调整图像的高度和宽度在PHP笨

public function resize() { 
 
\t \t $config['width'] = $this->input->post('width'); 
 
\t \t $config['height'] = $this->input->post('height'); 
 
\t \t $config['maintain_ratio'] = TRUE; 
 
\t \t $config['source_image'] = './uploads1/book.jpg'; 
 
\t \t $config['new_image'] = './uploads1/book_new.jpg'; 
 
\t \t $this->image_lib->initialize($config); 
 
\t \t $resize = $this->image_lib->resize(); 
 
\t \t 
 
\t }

如何调整在PHP笨图像的高度和宽度,只有高度没有调整正确,但宽度我得到

+0

添加您的代码并解释您在这样做时面临的问题。 –

+0

您是否收到错误?你没有给我们太多的信息来在这里工作。 – flauntster

+0

欢迎使用堆栈溢出。你已经尝试过这么做了吗?请回顾[预计需要多少研究工作?](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users)。堆栈溢出不是一种编码服务。您需要研究您的问题,并尝试在发布之前亲自编写代码。如果遇到某些特定问题,请返回并包含[最小,完整和可验证示例](https://stackoverflow.com/help/mcve)以及您尝试的内容摘要,以便我们提供帮助。 – Sand

回答

0
$this->load->library('image_lib'); 
if (!empty($_FILES['advert_image'])) { 

       $filename = substr(md5(time()), 0, 28) . strrchr($_FILES['advert_image']['name'], '.'); 
       $config['upload_path'] = 'public/events/images/'; 

       $config['allowed_types'] = 'jpg|jpeg|png|JPG|JPEG|PNG|BMP|bmp|gif|GIF'; 
       $config['file_name'] = $filename; 

       $config['is_image'] = true; 

       $this->load->library('upload', $config); 
       $this->upload->initialize($config); 
       //$this->upload->do_upload('advert_image'); 
       //start resize image 
       if (!$this->upload->do_upload('advert_image')) { 
        echo "error" . count; 
       } else { 
        $image_data = $this->upload->data(); 

        $configer = array(
         'image_library' => 'gd2', 
         'source_image' => $image_data['full_path'], 
         'maintain_ratio' => TRUE, 
         'width' => 480, 
         'height' => 480, 
        ); 
        $this->image_lib->clear(); 
        $this->image_lib->initialize($configer); 
        $this->image_lib->resize(); 
       } 
       //end resize 
       $profile_pic = isset($filename) ? $filename : ""; 
      } 
+0

这是代码不工作在我的控制器 –

0

您必须在设置配置值后初始化库以使用它:

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

确保高度的输入值不是空的!

相关问题