How do I resize an image in codeIgniter?
-
Dear DI lovers, I have been trying to create image thumbnill in codeigniter. the image_library does not works to resize. My code is below $settings['maintain_ratio'] = TRUE; $settings['image_library'] = 'gd2'; $settings['create_thumb'] = TRUE; $settings['quality'] = '70%'; $settings['width'] = 50; $settings['height'] = 50; $settings['new_image'] ='./uploads/profile/'.$random_img_id.'.jpg'; $settings['source_image'] = './uploads/'.$random_img_id.'.jpg'; $this->load->library('image_lib',$settings); $this->image_lib->resize();
-
Answer:
1. Check whether the target directory have write permission.. 2. Check you didn't load the "image_lib" library twice.. and this is the code which I am using currently $this->load->library('image_lib'); $config['image_library'] = 'gd2'; $config['source_image'] = "Mention your source location here"; $config['create_thumb'] = TRUE; $config['maintain_ratio'] = TRUE; $config['height'] = "New Width"; $config['width'] = "New Height"; $config['new_image'] = "destination location";//you should have write permission here.. $this->image_lib->initialize($config); $this->image_lib->resize();
Ankur Rastogi at Quora Visit the source
Other answers
$upload_conf = array( 'upload_path' => realpath('./uploads/member/'), 'allowed_types' => 'gif|jpg|jpeg|png', 'max_size' => '300000', 'encrypt_name' => true, ); $this->load->library('upload'); $this->upload->initialize( $upload_conf ); $field_name = 'ProfilePic'; if ( !$this->upload->do_upload('ProfilePic','')){ $error['upload']= $this->upload->display_errors(); }else{ $upload_data = $this->upload->data(); $resize_conf = array( 'upload_path' => realpath('./uploads/member/thumb/'), 'source_image' => $upload_data['full_path'], 'new_image' => $upload_data['file_path'].'/thumb/'.$upload_data['file_name'], 'width' => 250, 'height' => 250); $this->load->library('image_lib'); $this->image_lib->initialize($resize_conf); // do it! if ( ! $this->image_lib->resize()){ // if got fail. $error['resize'] = $this->image_lib->display_errors(); }else{ $data_to_store['ProfilePic'] = $upload_data['file_name']; $data1['ProfilePic'] = $upload_data['file_name']; $this->session->set_userdata($data1); } }
Nikunj Prajapati
Related Q & A:
- How do I convert the image into ASCII format?Best solution by Stack Overflow
- How can i crop an image?Best solution by Stack Overflow
- How can I put an image for my background on Myspace?Best solution by Yahoo! Answers
- How do I resize the google search bar?Best solution by Stack Overflow
- How can I resize the yahoo page?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.