2015-07-09 19 views
2

我试图通过照片数组循环,并调整每个照片两次。一次用于拇指,然后用于全尺寸图像。在第一个循环中一切正常,但第二,第三,第四等没有创建缩略图版本。我无法弄清楚我做错了什么。任何人都可以从下面的代码中看到我的错误?Codeiginter多个图像调整大小不按预期工作

$this->load->library('image_lib'); 
foreach($photos as $current => $photo) {     

    // Create Thumb 
    $thumb_config = array(); 
    $thumb_config['create_thumb'] = TRUE; 
    $thumb_config['image_library'] = 'gd2'; 
    $thumb_config['source_image'] = $photo['full_path']; 
    $thumb_config['maintain_ratio'] = TRUE; 
    $thumb_config['width'] = 550; 
    $thumb_config['height'] = 550; 

    $this->image_lib->clear(); 
    $this->image_lib->initialize($thumb_config); 
    $this->image_lib->resize(); 
    // Resize Photo 
    $resize_config = array(); 
    $resize_config['create_thumb'] = FALSE; 
    $resize_config['image_library'] = 'gd2'; 
    $resize_config['source_image'] = $photo['full_path']; 
    $resize_config['maintain_ratio'] = TRUE; 
    $resize_config['width'] = 1500; 
    $resize_config['height'] = 1500; 

    $this->image_lib->clear(); 
    $this->image_lib->initialize($resize_config); 
    $this->image_lib->resize(); 
} 
+0

看看我的答案... [codeigniter调整图像大小和创建缩略图](http://stackoverflow.com/a/11505260/782535) –

回答

1

尝试resize()这样以后把你的clear() S:

这是我目前的结构:

|--- assets 
| |--- images 
| | |--- changed 
| | |--- test.png 
| | |--- test2.jpg 

后,我运行下面的代码,我有:

|--- assets 
| |--- images 
| | |--- changed 
| | | |--- test.png 
| | | |--- test2.jpg 
| | | |--- test_thumb.png 
| | | |--- test2_thumb.jpg 
| | |--- test.png 
| | |--- test2.jpg 

这是我使用的代码:

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

    $photos = array(
     array(
      "full_path" => "assets/images/", 
      "name" => "test.png" 
     ), 
     array(
      "full_path" => "assets/images/", 
      "name" => "test2.jpg" 
     ), 
    ); 
    foreach ($photos as $current => $photo) { 
     // Create Thumb 
     $thumb_config = array(); 
     $thumb_config['create_thumb'] = TRUE; 
     $thumb_config['image_library'] = 'gd2'; 
     $thumb_config['source_image'] = $photo['full_path'] . $photo['name']; 
     $thumb_config['new_image'] = $photo['full_path'] . "changed/" . $photo['name']; 
     $thumb_config['maintain_ratio'] = TRUE; 
     $thumb_config['width'] = 550; 
     $thumb_config['height'] = 550; 

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

     if (!$this->image_lib->resize()) { 
      echo $this->image_lib->display_errors(); 
     } 
     $this->image_lib->clear(); 

     // Resize Photo 
     $resize_config = array(); 
     $resize_config['create_thumb'] = FALSE; 
     $resize_config['image_library'] = 'gd2'; 
     $resize_config['source_image'] = $photo['full_path'] . $photo['name']; 
     $resize_config['new_image'] = $photo['full_path'] . "changed/" . $photo['name']; 
     $resize_config['maintain_ratio'] = TRUE; 
     $resize_config['width'] = 1500; 
     $resize_config['height'] = 1500; 

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

     if (!$this->image_lib->resize()) { 
      echo $this->image_lib->display_errors(); 
     } 
     $this->image_lib->clear(); 
    } 
+0

谢谢,但它仍然不会创建其他缩略图。它很奇怪,因为它做了大的调整,只是不会制作缩略图。 – Tommy

+0

尝试添加错误处理程序以查看所得结果 – CodeGodie

+0

它从不出错。我甚至做了一个$ thumb = $ this-> image_lib-> resize();然后var_dump($ thumb),并返回true,如函数成功完成。我完全沉迷于这一个。 – Tommy

相关问题