【问题标题】:How to resize image before upload and store in database in codeingiter如何在上传和存储在codeigniter中的数据库之前调整图像大小
【发布时间】:2017-10-09 02:48:41
【问题描述】:

这是我的控制器代码

`

$type=explode('.', $_FILES['picture']['name']);

                        $type = $type[count($type)-1];



                        $url = "uploads/products/images/".uniqid(rand()).".".$type;

                        if(in_array($type, array('jpg','jpeg','png','JPG','JPGE','PNG') ) )
                        {
                            if(is_uploaded_file($_FILES['picture']['tmp_name']))
                            {
                               move_uploaded_file($_FILES['picture']['tmp_name'],$url);
                            }
                        }
                        '

【问题讨论】:

    标签: php image codeigniter file upload


    【解决方案1】:

    由于您使用的是 CodeIgniter,它有自己的 Image Manipulation 类:

    https://www.codeigniter.com/userguide3/libraries/image_lib.html

    $config['image_library'] = 'gd2';
    $config['source_image'] = '/path/to/image/mypic.jpg';
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['width']         = 75;
    $config['height']       = 50;
    
    $this->load->library('image_lib', $config);
    
    $this->image_lib->resize();
    

    将宽度和高度变量设置为调整图像大小所需的值。

    【讨论】:

    • $url = "uploads/products/images/".uniqid(rand()).".".$type;这里我传递的是destination_folder/image_name.image_type,这可能是文件夹/mypic.jpg。如何以这种格式调整图像大小? $url 的唯一值存储在数据库中。
    猜你喜欢
    • 2015-06-19
    • 2017-04-27
    • 2014-03-07
    • 1970-01-01
    • 2016-12-22
    • 1970-01-01
    • 2021-11-30
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多