dongyan2469 2012-01-16 16:24
浏览 39
已采纳

调整源的图像大小并使用Codeigniter设置上载路径

I'm building an image gallery with Codeigniter everything is going good so far, but I had a quick question about image resizing.

Basically I upload the source image, and make create an id then store it in that path /uploads/$id/source.jpg. Then I try to create two new images of the source image, a thumbnail and a medium image with a watermark.

When using Codeigniter's Image Manipulation Class can you set a file name and a upload path? And when you give it the source image does it modify the source image or does it make a copy?

public function generateThumnail($source, $screenid) {
        $config['image_library'] = 'gd2';
        $config['source_image'] = "$source";
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 75;
        $config['height'] = 50;

        //Not sure how I set the upload path and file name.
        $this->load->library('image_lib', $config); 
        $this->image_lib->resize();

        //TODO: Code to be added later
        $this->image_lib->clear();
}

The upload path and the file name aren't include because I'm not sure how to add them. Is there any way to add them?

  • 写回答

1条回答 默认 最新

  • dpkpaxhzffixp8426 2012-01-16 16:29
    关注

    Yes, you can specify an upload path but by using the File Uploading Class, not the Image Manipulation Class.

    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width'] = '1024';
    $config['max_height'] = '768';
    
    $this->load->library('upload', $config);
    

    http://codeigniter.com/user_guide/libraries/file_uploading.html

    CodeIgniter will create a copy of the image if you tell it to.

    Creating a Copy

    The resizing function will create a copy of the image file (and preserve the original) if you set a path and/or a new filename using this preference:

    $config['new_image'] = '/path/to/new_image.jpg';
    

    Notes regarding this preference:

    • If only the new image name is specified it will be placed in the same folder as the original
    • If only the path is specified, the new image will be placed in the destination with the same name as the original.
    • If both the path and image name are specified it will placed in its own destination and given the new name.

    http://codeigniter.com/user_guide/libraries/image_lib.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog