Codeigniter图像resize()缩略图名称应具有相同名称

iklwldmw  于 2022-12-07  发布在  其他
关注(0)|答案(3)|浏览(98)

在这里我的控制器文件这工作正常,除了在拇指文件夹名称得到更改为converted_thumb的例子:我原来的图像名称是converted.jpg,但在拇指文件夹中,它保存为converted_thumb,所以我想从图像名称中删除_thumb,请解决这个问题

public function do_upload() {
$config['upload_path'] = './uploads';  //  uploaded file store here
        $config['allowed_types'] = 'jpg|png|jpeg|gif';
        $config['max_size'] = ' 2097152';
        $this->load->library('upload', $config);
        if ($this->upload->do_upload()) {

            $data = $this->upload->data();

            //create  copy of image

            $configs['image_library'] = 'gd2';
            $configs['source_image'] = $data['full_path'];
            $configs['new_image'] = 'uploads/thumbs/'; //resize image will save here
            $configs['create_thumb'] = 'false';
            $configs['width'] = '250';
            $configs['height'] = '250';
            $this->load->library('image_lib', $configs);
            $this->image_lib->resize();

            $image_name = $data['file_name'];
            //$full_path = $data['full_path'];
            $post = array(
                'product_name' => $image_name,
                'product_path' => $configs['new_image'].$image_name
            );

            $this->db->insert('project', $post);
        } else {
            echo $this->upload->display_errors();
        }
    }

}
svdrlsy4

svdrlsy41#

为什么你不喜欢那个大拇指?它就是用来做这个的。不管怎样,做这个。

rename("<?php echo base_url()?>/uploads/thumbs/YOUR_FILE_NAME_THUMBS", "<?php echo base_url()?>/uploads/thumbs/YOUR_FILE_NAME");
nfg76nw0

nfg76nw02#

$configs数组中尝试thumb_marker

$configs['image_library'] = 'gd2';
  $configs['source_image'] = $data['full_path'];
  $configs['new_image'] = 'uploads/thumbs/'; //resize image will save here
  $configs['create_thumb'] = 'false';
  $configs['thumb_marker'] = ''; //Add this in your config array empty string

然后'_thumb'将不会添加到新创建的文件中。Source了解更多详细信息。

7z5jn7bk

7z5jn7bk3#

只需将thumb_marker添加到您的config数组并将其设置为FALSE

$configs['image_library'] = 'gd2';
 $configs['source_image'] = $data['full_path'];
 $configs['new_image'] = 'uploads/thumbs/'; //resize image will save here
 $configs['create_thumb'] = 'false';
 $configs['thumb_marker'] = FALSE; //this will remove the "_thumb" to your thumb image name 
 $configs['width'] = '250';
 $configs['height'] = '250';

相关问题