Codeigniter 多图像调整大小未按预期工作

Codeiginter Multiple Image Resize Not Working As Expected

我正在尝试遍历一组照片并将每张照片调整两次。一次用于拇指,然后一次用于全尺寸图像。第一个循环一切正常,但第二个、第三个、第四个等从未创建缩略图版本。我不知道我做错了什么。谁能从下面的代码中看出我的错误?

$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(); 
}

尝试像这样将 clear() 放在 resize() 之后:

这是我当前的结构:

|--- 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();
    }