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

[eluser]the_unforgiven[/eluser]
Nothing still, still not resizing and not puttin the thumb into thumbs folder.
#12

[eluser]the_unforgiven[/eluser]
And i cant seem to echo $config[‘source_image’]
#13

[eluser]LynxCoder[/eluser]
[quote author="the_unforgiven" date="1334310470"]And i cant seem to echo $config[‘source_image’][/quote]

Ok, are you 100% sure that $config['sourceimage'] contains the correct path? Can you echo the two component parts - the path and the filename? That would confirm that the right value is being passed.

If the new_image tag is now set correctly to include a filename, and its not resizing, that would suggest to me that its not finding the original file. Do you have CI set to show errors? It may also be worth looking in the CI log to find out is anything is being mentioned in there?

Rich
#14

[eluser]the_unforgiven[/eluser]
Heres the code again

Code:
function _do_upload_file()
{
                $this->gallery_path = realpath(APPPATH . '/../assets/uploads/userfiles/');
  $thpath = realpath(APPPATH.'/../assets/uploads/userfiles/thumbs/');
  
     //upload path and config
  $config = array(
   'allowed_types' => 'jpg|jpeg|gif|png|pdf',
   '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['image_library'] = 'gd2';
   $config['create_thumb'] = TRUE;
   $config['source_image'] = $this->upload->upload_path.$this->upload->file_name;
   $config['new_image'] = $thpath . '_thumb.jpg';
   $config['maintain_ratio'] = TRUE;
   $config['thumb_marker'] = '_thumb';
   $config['width'] = 150;
   $config['height'] = 100;
  
   $this->load->library('image_lib', $config);
   $this->image_lib->initialize($config);
   $this->image_lib->resize();
    
   if (!$this->image_lib->resize()){
          $this->form_validation->set_message('_do_upload_file', $this->upload->display_errors());              
   }
  }
}

I don't get any errors, it uploads, but just doesn't resize and put the rezised image into thumbs folder. Checking the CI Log now to see if there's anything in there.
#15

[eluser]the_unforgiven[/eluser]
Nothing in logs to state otherwise, plus I always have the php_error log console open on my mac whilst coding.
#16

[eluser]LynxCoder[/eluser]
[quote author="the_unforgiven" date="1334312348"]

Code:
$config['height'] = 100;

Ok, before the above line add

Code:
echo $this->upload->upload_path.$this->upload->file_name . "<BR>";

That will do two things, provide that the resize code is being executed, and also output where it thinks its finding the file. I would then manually check that that path is exactly correct, and that the file is there.

Also might just be worth removing the '_' before the thumbs.jpg - filename in 'new_image' it shouldn't cause a problem on a Mac (im on a iMac too btw) but just in case.

Everything in the code looks right to me, so its got to be related to either getting the original image or resaving the resized version in my view.

Rich
#17

[eluser]the_unforgiven[/eluser]
Well f**k a duck!!!

My mistake after about two hours last night and a good hour this morning foudn it with your help too of course, i'd not specified the path and url corrdtly so i went to download the image manip tut from nettuts and looked at the code Burak does and noticed the vars for gallery path and gallery url were inc orrect and what do you know it now upload orginal image and a thumb to thumbs folder.


LynxCoder (like the username by the way) thanks for you help much appreciated,
#18

[eluser]the_unforgiven[/eluser]
My next question is what do i use to get the thumb stored to the db, currently have:

Code:
$image_data = $this->upload->data();
$data['item_img'] = $image_data['file_name'];

At the end of my model, so now i have a new row in my database called thumb and want to store the thumb ion the database from the thumbs folder.

How does one acheive this?
#19

[eluser]LynxCoder[/eluser]
[quote author="the_unforgiven" date="1334315251"]
LynxCoder (like the username by the way) thanks for you help much appreciated,[/quote]

Excellent! Glad it all works! My usual point to start debugging is to echo out the variables and say what have i buggered up!!! Your welcome anyway!

[quote author="the_unforgiven" date="1334315630"]My next question is what do i use to get the thumb stored to the db, currently have:

Code:
$image_data = $this->upload->data();
$data['item_img'] = $image_data['file_name'];
[/quote]

I'm assuming that your storing the reference to the filename and not the actual thumbnail? In which case its just a simple case of doing

Code:
$this->db->where('uniqueid',$UID);
$this->db->update('tablename',$data);

Assuming that a record already exists in the table and your just updating it with the thumbnail filename - in which case you should already have the $UID - obviously replace 'uniqueid' and 'tablename' with the appropriate values.

EDIT: I'm assuming that the fieldname in the table is 'item_img', if not, then you need to change $data['item_img'] to be $data['fieldname'], replacing fieldname with the appropriate fieldname of course!!

Alternatively, if you are just adding the thumbnail as a fresh record then

Code:
$this->db->insert('tablename',$data);

plus any other data your looking to store alongside it of course!

Assuming that all your thumbnails are stored in the same folder, then you only need to store the actual filename in the DB, not the path, which will reduce the data footprint of the DB. If thumbnails are stored in various places, then you'll need to store the path too.
#20

[eluser]the_unforgiven[/eluser]
All images are uploaded to uploads folder the orginals.

Thumbs are uploaded to uploads/thumbs then the filename which will be for example:

aimage_thumb.png

whereas the orginal will just be aimage.png

soo what i want to do using this model i have you will see the commented out line is what i want to achieve:

Code:
function addItem(){
  $data = array(  
   'category_id' => $this->input->post('categories'),
   'customerNumber' => $this->input->post('customerNumber'),
   'item_name' => $this->input->post('name'),
   'item_description' => $this->input->post('desc'),
   'item_price' => $this->input->post('price'),
   'posted_by' => $this->input->post('customer'),
  
  );
  $image_data = $this->upload->data();
  $data['item_img'] = $image_data['file_name'];
  // So i presume i will need $data['item_img'] = $image_data['file_name']; again but with thumb in the $data not item_img but what will go inside the $image_data? if i put file_name again it just puts in the original image but i want it to store the thumb that was created.

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




Theme © iAndrew 2016 - Forum software by © MyBB