Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top