title: Codeigniter Image resize and change any image extension to .png extension
body: <p>I'm trying to add functionality like if any user upload image two function occur</p>
  
  <ol>
  <li>Image resizes to mentioned requirement</li>
  <li>Image of any extension changed to .png extension.</li>
  </ol>
  
  <p>This is my controller file</p>
  
  <pre><code>    &lt;?php
  class Form extends CI_Controller {
  
      function __construct()
      {
          parent::__construct();
          $this-&gt;load-&gt;helper(array('form', 'url'));
      }
  
      public function index() {
          $this-&gt;load-&gt;view('Form/form.php');
          $this-&gt;load-&gt;view('Home/header.php');
      }
  
      public function do_upload() {
  
          $this-&gt;load-&gt;library('form_validation');
          $this-&gt;form_validation-&gt;set_rules('Firstname', 'Firstname', 'required');
          $this-&gt;form_validation-&gt;set_rules('Middlename', 'Middlename');
          $this-&gt;form_validation-&gt;set_rules('Lastname', 'Lastname', 'required');
          $this-&gt;form_validation-&gt;set_rules('Fathername', 'Fathername', 'required');
          $this-&gt;form_validation-&gt;set_rules('Mothername', 'Mothername', 'required');
          $this-&gt;form_validation-&gt;set_rules('DOB', 'DOB', 'required');
          $this-&gt;form_validation-&gt;set_rules('Mobile', 'Mobile', 'required');
          $this-&gt;form_validation-&gt;set_rules('Postalcode', 'Postalcode', 'required');
          $this-&gt;form_validation-&gt;set_rules('userfile', 'Image', 'required');
          $this-&gt;form_validation-&gt;set_rules('Address', 'Address', 'required');
          $this-&gt;form_validation-&gt;set_rules('Branch', 'Branch', 'required');
          $this-&gt;form_validation-&gt;set_rules('Email', 'Email', 'required');
          $this-&gt;form_validation-&gt;set_rules('Classronum', 'ClassRollNumber', 'required');
          $this-&gt;form_validation-&gt;set_rules('Unironum', 'UniversityRollNumber', 'required');
          $this-&gt;form_validation-&gt;set_rules('Comment', 'Comment', 'required');
  
          $config['upload_path'] = './uploads/';
          $config['allowed_types'] = 'gif|jpg|png';
          $config['max_size']='1000';
          $config['max_width']='1024';
          $config['max_height']='1000';
  
          $this-&gt;load-&gt;library('upload', $config);
          $this-&gt;upload-&gt;initialize($config); 
  
          if ( ! $this-&gt;upload-&gt;do_upload() &amp;&amp; $this-&gt;form_validation-&gt;run() == FALSE)
          {
              $error = array('error' =&gt; $this-&gt;upload-&gt;display_errors());
              $this-&gt;load-&gt;view('Form/form', $error);
              $this-&gt;load-&gt;view('Home/header.php');
          } else {
              $data = $this-&gt;upload-&gt;data();
              $this-&gt;resize($data['upload_data']['full_path'], $data['upload_data']['file_name']);
              $this-&gt;load-&gt;model('form_model');
              $this-&gt;load-&gt;view('Form/success', $data);
              $this-&gt;load-&gt;view('Home/header.php');   
              $this-&gt;form_model-&gt;form_fill($data['file_name']);
          }
      }
  
      public function resize($path, $file) {
          $config['image_library'] = 'ImageMagick';
          $config['library_path']='/usr/bin';
          $config['source_image']='uploads/'.$name.'.'.$m[1];
          $config['new_image']='uploads/'.$name.'.'.$png;
          $objImage = new CI_Image_lib($config);
          $config['source_image']=$path;
          $config['create_thumb']=TRUE;
          $config['maintain_ratio']=TRUE;
          $config['width']=150;
          $config['height']=75;
          $config['new_image']='./uploads/'.$file;
  
          $this-&gt;load-&gt;library('image_lib', $config);
          $this-&gt;image_lib-&gt;resize();
      }   
  }
  ?&gt;
  </code></pre>
  
  <p>This is my model file</p>
  
  <pre><code>    &lt;?php
  class Form_model extends CI_Model {
      public function form_fill($file) {
          $this-&gt;load-&gt;database();
          $id = $this-&gt;input-&gt;post('id');
          $firstname = $this-&gt;input-&gt;post('Firstname');
          $middlename = $this-&gt;input-&gt;post('Middlename');
          $lastname = $this-&gt;input-&gt;post('Lastname');
          $fathername = $this-&gt;input-&gt;post('Fathername');
          $mothername = $this-&gt;input-&gt;post('Mothername');
          $dob = $this-&gt;input-&gt;post('DOB');
          $mobile = $this-&gt;input-&gt;post('Mobile');
          $postalcode = $this-&gt;input-&gt;post('Postalcode');
          $address = $this-&gt;input-&gt;post('Address');
          $photo = $this-&gt;input-&gt;post('userfile');
          $branch = $this-&gt;input-&gt;post('Branch');
          $email = $this-&gt;input-&gt;post('Email'); 
          $classrollno = $this-&gt;input-&gt;post('Classronum');
          $universityrollno = $this-&gt;input-&gt;post('Unironum');
          $comment = $this-&gt;input-&gt;post('Comment');           
  
          $data = array(
              'firstname' =&gt; $this-&gt;input-&gt;post('Firstname'),
              'middlename' =&gt; $this-&gt;input-&gt;post('Middlename'),
              'lastname' =&gt; $this-&gt;input-&gt;post('Lastname'),
              'fathername' =&gt; $this-&gt;input-&gt;post('Fathername'),
              'mothername' =&gt; $this-&gt;input-&gt;post('Mothername'),
              'dob' =&gt; $this-&gt;input-&gt;post('DOB'),
              'mobile' =&gt; $this-&gt;input-&gt;post('Mobile'),
              'postalcode' =&gt; $this-&gt;input-&gt;post('Postalcode'),
              'address' =&gt; $this-&gt;input-&gt;post('Address'),
              'photo' =&gt; $file,
              'branch' =&gt; $this-&gt;input-&gt;post('Branch'),
              'email' =&gt; $this-&gt;input-&gt;post('Email'),
              'classrollno' =&gt; $this-&gt;input-&gt;post('Classronum'),
              'universityrollno' =&gt; $this-&gt;input-&gt;post('Unironum'),
              'comment' =&gt; $this-&gt;input-&gt;post('Comment')
              );
          $this-&gt;db-&gt;insert('student', $data);
      }
  }
  ?&gt;  
  </code></pre>