Welcome Guest, Not a member yet? Register   Sign In
image manipulation, resize adn unique name
#1

[eluser]the_unforgiven[/eluser]
Hi guys,

I currently have this code which uploads fine to the server folder in the config but i need to resize it them place into thumbs folder with a unqiue name, so can someone adviose how and best way to do it based on my code please?

Code:
function _do_upload_file()
{
     //upload path and config
  $config['upload_path']   = './assets/uploads/userfiles/';
     $config['allowed_types'] = 'png|jpg|gif|jpeg';
     $config['max_size'] = '3000';

     $this->load->library('upload', $config);
  $this->upload->initialize($config);
  
     if (!$this->upload->do_upload())
     {
         $this->form_validation->set_message('_do_upload_file', $this->upload->display_errors());
         return FALSE;
     }
     else
     {
   $filedata = $this->upload->data();
   $this->filename = $filedata['file_name'];
  
         return TRUE;
  }
  

}
#2

[eluser]the_unforgiven[/eluser]
Can anyone help me based on what I have put already??
#3

[eluser]NotDior[/eluser]
Looks like the function write_file() might help you out.

http://ellislab.com/codeigniter/user-gui...elper.html
#4

[eluser]the_unforgiven[/eluser]
write_file() helper not what i was after.

I have this code
Code:
function _do_upload_file()
{
     //upload path and config
  $config = array(
   'allowed_types' => 'jpg|jpeg|gif|png',
   'upload_path' => $this->gallery_path,
   'max_size' => 3000,
   'overwrite' => false,
      'remove_spaces' => true
  );

     $this->load->library('upload', $config);
  $this->upload->initialize($config);
  
     if (!$this->upload->do_upload())
     {
         $this->form_validation->set_message('_do_upload_file', $this->upload->display_errors());
         return FALSE;
     }
     else
     {
   $config = array(
    'image_library' => 'gd2',
    'create_thumb' => TRUE,
    'source_image' => $this->upload->upload_path.$this->upload->file_name,
    'new_image' => $this->gallery_path . '/thumbs',
    'maintain_ration' => true,
    'width' => 150,
    'height' => 100
   );
   $this->load->library('image_lib', $config);
    
   if (!$this->image_lib->resize()){
          $this->form_validation->set_message('_do_upload_file', $this->image_lib->display_errors());              
   }

  }
  

}

Which currently uploads files to assets/uploads/userfiles/imagename.jpg for example but now the code above should resize the image uploaded adn then place into a folder called thumbs inside assets/uploads/userfiles/thumbs for instance is what I have setup, can any one help me on this?

Have I missed something or done something wrong?
#5

[eluser]NotDior[/eluser]
Did you check the permission on your thumbs folder to make sure it's writeable? The code looks good to me on the surface.
#6

[eluser]the_unforgiven[/eluser]
All files are local on Mac and all have read write permissions, it uploads but doesn't re-size and then put into thumbs folder so obviously there's something not right within the code I'm not sure of.
#7

[eluser]the_unforgiven[/eluser]
Anyone?
#8

[eluser]the_unforgiven[/eluser]
????

????
#9

[eluser]LynxCoder[/eluser]
[quote author="the_unforgiven" date="1334245310"]
Which currently uploads files to assets/uploads/userfiles/imagename.jpg for example but now the code above should resize the image uploaded adn then place into a folder called thumbs inside assets/uploads/userfiles/thumbs for instance is what I have setup, can any one help me on this?

Have I missed something or done something wrong?[/quote]

Ok, well just to confirm, the file is uploading ok - but not resizing or giving a unique name? Does the code provide any error messages? Have you tried echoing the value of $config['source_image'] to check that its providing the correct URL?

Ah - just realised one thing the UserGuide for Image Manipulation says $config['new_image'] provides the name and path, your only providing the path - so is the resized file being created in the $this->gallery_path directory and called 'thumbs'. If not, it could be that if the directory exists, the file system will not allow a file to have the same name as a directory, without an extension. Try adding a temporary file name ...

Code:
'new_image' => $this->gallery_path . '/thumbs/itworks.jpg',

Rich
#10

[eluser]the_unforgiven[/eluser]
Yes it uploads but does not resize correct!

$config[‘source_image’] not tried but will try now!

I'll also try
Code:
'new_image' => $this->gallery_path . '/thumbs/itworks.jpg',




Theme © iAndrew 2016 - Forum software by © MyBB