• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Image Manipulation Library Question

#1
[eluser]mikegeorgeff[/eluser]
Is there a way to resize an image twice. I have a form where I'm uploading an image and I need a large view and a smaller image. I currently have the smaller image size working but I can't figure out how to resize the source image.

Here is the code I have:

Code:
function addProduct()
    {
        $now = date("Y-m-d H:i:s");
        $data = array(
            'name' => $this->input->post('name'),
            'desc' => $this->input->post('desc'),
            'category_id' => $this->input->post('category_id'),
            'featured' => $this->input->post('featured'),
            'price' => $this->input->post('price'),
            'shipping' => $this->input->post('shipping'),
            'date' => $now
        );
        
        if($_FILES)
        {
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|jpeg|png';
            $config['max_size'] = '2048';
            $config['remove_spaces'] = TRUE;
            $config['overwrite'] = FALSE;
            
            $this->load->library('upload', $config);
            if(!$this->upload->do_upload('image'))
            {
                $this->upload->display_errors();
                exit();
            }
            
            $image_data = $this->upload->data();
            if($image_data['file_name'])
            {
                $data['image'] = $image_data['file_name'];
            }
            
            $config['source_image'] = $image_data['full_path'];
            $config['new_image'] = './uploads/thumbs/';
            $config['maintain_ratio'] = TRUE;
            $config['height'] = 143;
            $config['width'] = 100;
            
            $this->load->library('image_lib', $config);
            if(!$this->image_lib->resize())
            {
                $this->image_lib->display_errors();
                exit();
            }
            
            if($image_data['file_name'])
            {
                $data['thumbnail'] = 'thumbs/'.$image_data['file_name'];
            }
            
        }    
        
        $this->db->insert('product', $data);
    }

#2
[eluser]Mat-Moo[/eluser]
You can try my library (Image_moo in the sig)

#3
[eluser]Cristian Gilè[/eluser]
Code:
$config = array();

//first resize
$config['source_image'] = $image_data['full_path'];
$config['new_image'] = './uploads/thumbs/';
$config['maintain_ratio'] = TRUE;
$config['height'] = 143;
$config['width'] = 100;
            
$this->load->library('image_lib', $config);
$this->image_lib->resize();

//second resize
$config['new_image'] = './uploads/large/'; //change this path according to your needs
$config['height'] = 500; // change according to your needs
$config['width'] = 400;  // change according to your needs
            
$this->image_lib->initialize($config);

$this->image_lib->resize();


Cristian Gilè


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.