0

my controller:

  public function addgalleryProcess()
        {


            $height = $this->input->POST('height');
            $width = $this->input->POST('width');


            $config['upload_path'] = './assets/images/gallery';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '1000';
            $config['max_width']  = '';
            $config['max_height']  = '';
            $config['overwrite'] = TRUE;
            $config['remove_spaces'] = TRUE;

            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload())
            {
                  $error = array('error' => $this->upload->display_errors());
                  $this->load->view('admin/addgallery', $error);
            }
            else
            {

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

                //resize:

                $config1['image_library'] = 'gd2';
                $config1['source_image'] = $upload_data['full_path'];
                $config1['maintain_ratio'] = TRUE;
                $config1['create_thumb'] = TRUE;
                $config1['width'] = $width;
                $config1['height'] = $height;
                $this->load->library('image_lib', $config1); 
                $this->image_lib->resize();

                 $this->adminModel->galleryimages($upload_data);
                 $this->load->view('admin/homeView'); 
              }

my model:

public function galleryimages($image_data = array())
{

    $data = array(
    'image' => $image_data['file_name'],

    );

        $this->db->insert('gallery', $data);
}

Here image is uploaded properly and working, but resize is not working. I have to display the resized image with specified width and height. I am new to this. Thanking in advance.

Abin Jacob
  • 217
  • 6
  • 18

2 Answers2

0

Try this:

For image resize I suggest to use "TimThumb" TimThumb – PHP Image Resizer

https://www.binarymoon.co.uk/projects/timthumb/

I have use timthumb in my project like

<img src="<?php echo base_url('assets/common/timthumb') . '/timthumb.php?src=./assets/myuploads/myimagename.jpg&w=245&h=164'; ?>" alt="">

I have put timthumb.php in "assets" folder and I uploaded my images in "assets/myuploads" folder

0

Not to be to distracting, if you want to resize the image before upoading through the networks, you can javascript it to a canvas and then send the canvas image in toDataURL. This would help prevent someone from uploading something massive and your network and server struggle with it. This also depends if your client in a HTML client. The following Article can help with this,: https://stackoverflow.com/a/10334170/811827

Community
  • 1
  • 1
Cyberience
  • 972
  • 10
  • 15