Welcome Guest, Not a member yet? Register   Sign In
uploading and resizing images
#1

[eluser]zazvorniki[/eluser]
This is driving me a little nutty. I'm working on a user uploading a profile image, but if that image is too large I would like to resize it and then replace the original image. This way I'm not hosting huge images on my website.

Anyway, the first piece of code is working just fine. I'm uploading the original file to the right folder, but I'm having trouble with the resize and replace.

Code:
public function profilePic(){
  if (empty($this->user)) {
   redirect('/home/');
  }else{
   $config['upload_path'] = './uploads/';
   $config['file_name'] = $this->user->pen_name.'.jpg';
   $config['file_path'] = './uploads/'.$this->user->pen_name.'.jpg';
   $config['max-size'] = 2000;
   $config['create_thumb'] = TRUE;
   $config['overwrite'] = TRUE;
   $config['allowed_types'] = 'gif|jpg|png|jpeg';
   $this->load->library('upload', $config);
   if ( ! $this->upload->do_upload())
     {
      $error = array('error' => $this->upload->display_errors());
      var_dump($error);
    }else{
     $config2['image_library'] = 'gd2';
     $config2['source_image'] = $config['file_path'];
     $config2['new_image'] = './upload/'.$this->user->pen_name.'.jpg';
     $config2['maintain_ratio'] = TRUE;
     $config2['create_thumb'] = TRUE;
     $config2['thumb_marker'] = '_thumb';
     $config2['width'] = 200;
     $config2['height'] = 300;
     $config2['overwrite'] = TRUE;
     $this->load->library('image_lib',$config2);
     $this->load->library('upload', $config2);
     if ( ! $this->image_lib->resize())
           {
               echo $this->image_lib->display_errors();
           }else{
            $this->users_model->uploadPic($config2['new_image']);
            redirect($_SERVER['HTTP_REFERER']);
           }    
   }
  }
         }

Any help is much appreciated!

edit: sorry the closing brakets are off....I can't seem to get them formatted properly here.
#2

[eluser]jairoh_[/eluser]
let's break it down into pieces,

1. did it upload the huge files in uploads? if not, please post the error.
2. this code
Code:
$this->load->library('upload', $config2);
is unnecessary. you already initialized the upload library.
3. do you have gd library installed in your php?
4. does image_lib throws an error?
#3

[eluser]zazvorniki[/eluser]
[quote author="jairoh_" date="1370651433"]let's break it down into pieces,

1. did it upload the huge files in uploads? if not, please post the error.
2. this code
Code:
$this->load->library('upload', $config2);
is unnecessary. you already initialized the upload library.
3. do you have gd library installed in your php?
4. does image_lib throws an error?[/quote]

1. Yes, it does upload the original image
2. I only had that, because I was trying anything to see if it would work
3.yes, it it installed and working
4. no error, just wont resize and upload the new image
#4

[eluser]jairoh_[/eluser]
try reference the uploaded file as
Code:
$upload= $this->upload->data();

then change

Code:
$config2['source_image'] = $config['file_path'];
$config2['new_image'] = './upload/'.$this->user->pen_name.'.jpg';

into
Code:
$config2['source_image'] = $upload['full_path'];
$config2['new_image'] = $upload['full_path'];

because u want to overwrite it
#5

[eluser]zazvorniki[/eluser]
[quote author="jairoh_" date="1370732739"]try reference the uploaded file as
Code:
$upload= $this->upload->data();

then change

Code:
$config2['source_image'] = $config['file_path'];
$config2['new_image'] = './upload/'.$this->user->pen_name.'.jpg';

into
Code:
$config2['source_image'] = $upload['full_path'];
$config2['new_image'] = $upload['full_path'];

because u want to overwrite it[/quote]

Thank you! I also had to change the create thumbs to false.

Code:
$config2['create_thumb'] = FALSE;




Theme © iAndrew 2016 - Forum software by © MyBB