调整相同图像的大小2次

时间:2011-04-10 22:11:24

标签: php codeigniter image-manipulation image-uploading

我使用php脚本上传图片,我希望能够在图像太大的情况下更改图像的大小,然后创建相同图像的拇指,此时我的图像调整大小但是拇指是不是出于某种原因创建的......也没有错误。 这是脚本:

        if($image_data['image_width'] > 1024 || $image_data['image_height'] > 768)
      {


    $config_resize = array(
            'source_image' => $image_data['full_path'],
            'new_image' => "./uploads/",
            'overwrite' => true,
            'maintain_ratio' => true,
            'width' => 1024,
            'height' => 768
            );
     $this->load->library('image_lib', $config_resize);
     if(! $this->image_lib->resize())
       {
         echo $this->image_lib->display_errors();
       }


    $config_thumb = array(
        'source_image' => $config_resize['source_image'],
        'new_image' => "./uploads/thumbs/",
        'maintain_ratio' => true,
        'width' => 150,
        'height' => 100
        );
    $this->load->library('image_lib', $config_thumb);

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


      }

1 个答案:

答案 0 :(得分:2)

.....
.....  

    $config_thumb = array(
                'source_image' => $config_resize['source_image'],
                'new_image' => "./uploads/thumbs/",
                'maintain_ratio' => true,
                'width' => 150,
                'height' => 100
                );

$this->image_lib->initialize($config_thumb); // <--- !!!

并且不要加载库两次