Codeigniter图像库-在循环中创建缩略图不起作用

时间:2018-10-10 15:39:08

标签: codeigniter

当我尝试在循环中创建缩略图时,未创建缩略图。 get_all_content()仅返回1行,其列为video_thumbnail。列video_thumbnail的值为test.png

function update_thumbnail() {
        //search if missing thumbnails

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

        $results = $this->media_model->get_all_content();

        foreach($results as $row) {

            $image = $row->filename;

             if(strpos($row->filename,".png")!==false or strpos($row->filename,".jpg")!==false or strpos($row->filename,".jpeg")!==false or strpos($row->filename,".gif")!==false) {
                $link = FCPATH.'assets/media/images/'.$row->filename;

                 if(strpos($row->filename,".png")!==false) {
                    $thumbnail = FCPATH."assets/media/images/".str_replace(".png","",$row->filename)."_thumb.png";
                 }

                 if(file_exists($thumbnail)) {

                 //echo "EXIST - ".$thumbnail;
                 } else {

                    //create thumbnail
                        $config['image_library'] = 'gd2';
                        $config['source_image'] = $link;
                        $config['create_thumb'] = TRUE;
                        $config['maintain_ratio'] = TRUE;
                        $config['width']  = 100;
                        $config['height']  = 100;
                        $config['thumb_marker'] = '_thumb';
                        $this->image_lib->resize();
                        $this->image_lib->clear();
                        $this->image_lib->initialize($config);


                 }
             } 

             if(!empty($row->video_thumbnail)) {
             //video thumbnail
                 $link = FCPATH.'assets/media/images/'.$row->video_thumbnail;

                 if(strpos($row->video_thumbnail,".png")!==false) {
                    $thumbnail = FCPATH."assets/media/images/".str_replace(".png","",$row->video_thumbnail)."_thumb.png";
                 }


                 if(file_exists($thumbnail)) {

                 //echo "EXIST - ".$thumbnail;
                 } else {
                        //create thumbnail
                        $config['image_library'] = 'gd2';
                        $config['source_image'] = $link;
                        $config['create_thumb'] = TRUE;
                        $config['maintain_ratio'] = TRUE;
                        $config['width']  = 100;
                        $config['height']  = 100;
                        $config['thumb_marker'] = '_thumb';
                        $this->image_lib->resize();
                        $this->image_lib->clear();
                        $this->image_lib->initialize($config);

                 }


             }


        }


    }

为什么不创建缩略图?

0 个答案:

没有答案