Upload and resize image problem. |
Hello,
I have the below code and i want to upload and resize the image. The thing is that even though the inputs are changing the image is not uploaded.. I have the same code in some other functions too but i don't get any errors. Any thoughts on that? Controller: Code: public function update_user_data() { Model: Code: public function update_user_data($user_id, $image){ Even though i've done an extensive search in google i couldn't find anything.... //Life motto if (sad() == true) { sad().stop(); develop(); }
Try setting some debug conditions to see where it is failing.
So do an echo in each function to see how far it is getting. Also go to index.php in the set flag to 'testing' or 'development' to check any errors.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
One thing that stands out is you are not calling this function:
$this->image_lib->initialize($config);
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
(09-08-2018, 02:54 PM)ignitedcms Wrote: One thing that stands out is you are not calling this function: I have the exact same code in another form without the function call you mentioned and works like charm! I'm trying to figure it out... //Life motto if (sad() == true) { sad().stop(); develop(); }
OK if that's not the issue check first to see if the folders are being created etc.
I'd start by doing something very simple like creating a controller and form that uploads an image and puts it into a directory already created and crops and resizes it. If that works it is simply a flaw in your logic. Also check to see if gd2 is enabled in php settings. https://stackoverflow.com/questions/1921...age-resize
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
(09-08-2018, 08:27 PM)ignitedcms Wrote: OK if that's not the issue check first to see if the folders are being created etc. You can officially tell that i'm an idiot.... The ONLY thing was that i forgot to add "_multipart" in my form open script. Now it works fine! Thank you very much for your time guys! I appreciate it! //Life motto if (sad() == true) { sad().stop(); develop(); }
You have to use like this.
$this->load->library('image_lib'); foreach($results as $row) { $config['image_library'] = 'gd2'; $config['source_image'] = '/img/proizvodi/'.$row->proizvodid.'.jpg'; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 75; $config['height'] = 50; $this->image_lib->clear(); $this->image_lib->initialize($config); $this->image_lib->resize(); } You shouldn't load image_lib in foreach. Try to use the code below Image Resize Codeigniter Configuration You need to do simple configuration to resize images, set the configurations properties like image_library, source_image,create_thumb etc width, height as 50 * 50, For that we are going to use inbuilt image library gd2. // Configuration $config['image_library'] = 'gd2'; $config['source_image'] = './img/images/uploaded/'.$imgName.".jpeg"; $config['new_image'] = './img/images/uploaded/'.$imgName."_new.jpeg"; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 50; $config['height'] = 50; Load library After Configuration $this->load->library('image_lib', $config); Call the resize function // resize image $this->image_lib->resize(); // handle if there is any problem if ( ! $this->image_lib->resize()){ echo $this->image_lib->display_errors(); } // resize image $this->image_lib->resize(); // handle if there is any problem if ( ! $this->image_lib->resize()){ echo $this->image_lib->display_errors(); } resize() function resize the image file and create new image file in specified folder. You will get errors "$this->image_lib->display_errors()", if there is any problem while image manipulation. function imageResize50X50($imgName){ $img_path = realpath("img")."\\images\\uploaded\\".$imgName.".jpeg"; // Configuration $config['image_library'] = 'gd2'; $config['source_image'] = './img/images/uploaded/'.$imgName.".jpeg"; $config['new_image'] = './img/images/uploaded/'.$imgName."_new.jpeg"; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['width'] = 50; $config['height'] = 50; // Load the Library $this->load->library('image_lib', $config); // resize image $this->image_lib->resize(); // handle if there is any problem if ( ! $this->image_lib->resize()){ echo $this->image_lib->display_errors(); } } Hope this will help you. |
Welcome Guest, Not a member yet? Register Sign In |