Welcome Guest, Not a member yet? Register   Sign In
codeigniter image resize not working
#1

[eluser]Pokhara[/eluser]
hello friends, can't understand why this image resizing not working pls help

Code:
//updating article
    
    function updateArticle(){
    $data = array(
        'a_title'            =>$_POST['a_title'],
        'a_description'        =>$_POST['a_description'],
        'a_flash_news'         => $_POST['a_flash_news'],
        'a_content'            =>$_POST['a_content'],
        //'a_views'             => $_POST['a_views'],
        'a_image_caption'    =>$_POST['a_image_caption'],
        'a_audio_caption'    =>$_POST['a_audio_caption'],
        'a_video'            =>$_POST['a_video'],
        'a_video_caption'    =>$_POST['a_video_caption'],
        'a_channel'             =>$_POST['a_channel'],
        'a_grouping'        =>$_POST['a_grouping'],
        'a_status'            =>$_POST['a_status'],
        'a_breaking'        =>$_POST['a_breaking'],
        'a_hot'                =>$_POST['a_hot'],
        'a_category_id'        =>$_POST['a_category_id'],
        'a_featured'        =>$_POST['a_featured'],
        'a_tags'            =>$_POST['a_tags'],
        'a_author'            =>$_POST['a_author'],
        'a_date'            =>$_POST['a_date']
        );
        
        
        //UPLOAD IMAGE
        //some $config vars for image
        $config['upload_path'] = './images/articles';
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size'] = '0';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $config['max_width'] = '0';
        $config['max_height'] = '0';
        
        //for image resize
        $config['image_library'] = 'gd2';
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 320;
        $config['height'] = 320;
        
        $this->load->library('upload', $config);
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
        //upload main image
        if(!$this->upload->do_upload('a_image')){
            //$e = $this->upload->display_errors();
            //print_r($e);
        }
        
        $image = $this->upload->data();
        if($image['file_name']){
            $data['a_image'] = "images/articles/". $image['file_name'];
        }
        
        
        //UPLOAD THUMBNAIL
        unset($config);
        
        //now upload thumb
        //some $config vars for thumb
        $config['upload_path'] = './images/articles/thumb';
        $config['allowed_types'] = 'gif|jpg|jpeg|png|wav';
        $config['max_size'] = '0';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $config['max_width'] = '0';
        $config['max_height'] = '0';    
        $this->upload->initialize($config);
        
            if(!$this->upload->do_upload('a_thumbnail')){
            //$e = $this->upload->dispaly_errors();
            //print_r($e);exit();    
        }        
        
        $thumb = $this->upload->data();
            if($thumb['file_name']){
            $data['a_thumbnail'] = "images/articles/thumb/". $thumb['file_name'];
        }
        
        
        //UPLOAD AUDIO
        unset($config);
        
        //now upload thumb
        //some $config vars for thumb
        $config['upload_path'] = './audio';
        $config['allowed_types'] = 'mp3|gif|jpg|jpeg|png|wav';
        $config['max_size'] = '0';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $config['max_width'] = '0';
        $config['max_height'] = '0';    
        $this->upload->initialize($config);
        
            if(!$this->upload->do_upload('a_audio')){
            //$e = $this->upload->dispaly_errors();
            //print_r($e);exit();    
        }        
        
        $thumb = $this->upload->data();
            if($thumb['file_name']){
            $data['a_audio'] = "audio/". $thumb['file_name'];
        }

        //goes at last
        $this->db->where('id',$_POST['id']);
        $this->db->update('articles', $data);
        
    }
#2

[eluser]Cristian Gilè[/eluser]
source_image setting (image lib user guide) is not set. It sets the source image name/path. The path must be a relative or absolute server path, not a URL.

To avoid confusion use to separate arrays for upload and image libs initialization.

Code:
//UPLOAD IMAGE
        //some $config vars for image
        $config = array();
        $config['upload_path'] = './images/articles';
        $config['allowed_types'] = 'gif|jpg|jpeg|png';
        $config['max_size'] = '0';
        $config['remove_spaces'] = true;
        $config['overwrite'] = false;
        $config['max_width'] = '0';
        $config['max_height'] = '0';
        
        $this->load->library('upload', $config);

        //for image resize
        $img_array = array();
        $img_array['image_library'] = 'gd2';
        $img_array['maintain_ratio'] = TRUE;
        //you need this setting to tell the image lib which image to process
        $img_array['source_image'] = '/path/to/your/image/img.jpg';
        $img_array['width'] = 320;
        $img_array['height'] = 320;

        $this->load->library('image_lib', $img_array);
        $this->image_lib->resize();

        //upload main image
        if(!$this->upload->do_upload('a_image')){


Cristian Gilè
#3

[eluser]dhaulagiri[/eluser]
i am also having same problem

what is source image on the fly using upload library? what is the difference between image resizing and thumbnail ceation ?
#4

[eluser]Cristian Gilè[/eluser]
Quote:i am also having same problem

what is source image on the fly using upload library?

source_image is a setting for the image not for the upload library.
After uploading the image set the source_image to the path where the image was uploaded.

Quote:what is the difference between image resizing and thumbnail ceation ?

From the user guide:

Quote:$this->image_lib->resize()

The image resizing function lets you resize the original image, create a copy (with or without resizing), or create a thumbnail image.

For practical purposes there is no difference between creating a copy and creating a thumbnail except a thumb will have the thumbnail marker as part of the name (ie, mypic_thumb.jpg).

All preferences listed in the table above are available for this function except these three: rotation_angle, x_axis, and y_axis.


Cristian Gilè




Theme © iAndrew 2016 - Forum software by © MyBB