加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – codeigniter调整图像大小并创建缩略图

发布时间:2020-12-13 22:20:53 所属栏目:PHP教程 来源:网络整理
导读:嗨,根据ci文档,您可以使用image_lib调整图像大小,有些选项建议我们可以从该图像创建其他缩略图 create_thumb FALSE TRUE/FALSE (boolean) Tells the image processing function to create a thumb. Rthumb_marker _thumb None Specifies the thumbnail indic
嗨,根据ci文档,您可以使用image_lib调整图像大小,有些选项建议我们可以从该图像创建其他缩略图

create_thumb    FALSE   TRUE/FALSE (boolean)    Tells the image processing function to create a thumb.  R
thumb_marker    _thumb  None    Specifies the thumbnail indicator. It will be inserted just before the file extension,so mypic.jpg would become mypic_thumb.jpg    R

所以这是我的代码

$config_manip = array(
            'image_library' => 'gd2','source_image'  => "./uploads/avatar/tmp/{$this->input->post('new_val')}",'new_image'     => "./uploads/avatar/{$this->input->post('new_val')}",'maintain_ratio'=> TRUE,'create_thumb'  => TRUE,'thumb_marker'  => '_thumb','width'         => 150,'height'        => 150 
        );

        $this->load->library('image_lib',$config_manip);
        $this->image_lib->resize();

我会假设此代码调整我的图像大小,并创建一个缩略图,但我只获得一个具有指定尺寸的图像和_tump后缀

我也尝试添加此代码手动创建第二个图像,但它仍然无法工作,我只得到一个图像

$this->image_lib->clear();

$config_manip['new_image'] = 
"./uploads/avatar/thumbnail_{$this->input->post('new_val')}";

            $config_manip['width']     = 30 ;
            $config_manip['height']    = 30 ;
            $this->load->library('image_lib',$config_manip);
            $this->image_lib->resize();

解决方法

似乎路径是代码中的问题.我修改并测试了自己的工作原理.

public function do_resize()
{
    $filename = $this->input->post('new_val');
    $source_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/tmp/' . $filename;
    $target_path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatar/';
    $config_manip = array(
        'image_library' => 'gd2','source_image' => $source_path,'new_image' => $target_path,'maintain_ratio' => TRUE,'create_thumb' => TRUE,'thumb_marker' => '_thumb','width' => 150,'height' => 150
    );
    $this->load->library('image_lib',$config_manip);
    if (!$this->image_lib->resize()) {
        echo $this->image_lib->display_errors();
    }
    // clear //
    $this->image_lib->clear();
}

希望这对你有所帮助.谢谢!!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读