php - Codeigniter - Multiple Resize Image not working -


i've tried on clearing, un-setting config resizing orignal image different dimensions, no avail, under current controller code. upload_news_images() called when user selects images (orignal images uploaded, thumbs created shown user: (using ajax). when user hits submit form, i've resize each image using resize() funtions using different dimensions, no error being displayed.

<?php defined('basepath') or exit('no direct script access allowed');  class datahandler extends ci_controller {   public function insert_news(){       // uploaded images array       $uploaded_images = $this->input->post('uploads');        // move images         foreach($uploaded_images $img){           $j = 0;             for($k=0; $k<3; $k++){              if($k==0){                 $this->resize($img, 176, 176);              }              if($k==1){                 $this->resize($img, 360, 360);              }              if($k==2){                 $this->resize($img, 1024, 1024);              }             }          //rename("./uploads/tmp/orignals/".$img, "./uploads/images/news/orignals/".$img);       }           exit;          // insert news data second         $this->load->model("news_model");         $news = new news_model();          $news->title = $this->input->post('title');         $news->short_desc = $this->input->post('short_desc');         $news->desc = $this->input->post('description');         $news->pub_date = date("y/m/d h:i:s");         $news->active = $this->input->post('active');          $tr_id = $this->input->post('tr_id');         if($tr_id == ""){             $news->tr_id = null;         }else{             $news->tr_id = $this->input->post('tr_id');         }           $sp_id = $this->input->post('sp_id');         if($sp_id == ""){             $news->sp_id = null;         }else{             $news->sp_id = $this->input->post('sp_id');         }           $pl_id = $this->input->post('pl_id');         if($pl_id == ""){             $news->pl_id = null;         }else{             $news->pl_id = $this->input->post('pl_id');         }          $city_id = $this->input->post('city_id');         if($city_id == ""){             $news->city_id = null;         }else{             $news->city_id = $this->input->post('city_id');         }         $news->save();          $this->session->set_flashdata('i', 1);         redirect(site_base_url.'admin/addnews');   }    public function upload_news_images() {     $id=$this->generaterandomstring();      $source_image = $_files['file']['tmp_name'];     $source_name = $_files['file']['name'];       $file_extension = pathinfo($source_name,pathinfo_extension);      //echo aappath;exit;     $tmp_upload_path = "./uploads/tmp/orignals/";     $tmp_upload_thumb_path = "./uploads/tmp/thumbs/";      $new_source = $tmp_upload_path.$id.".".$file_extension;     $new_thumb = $tmp_upload_thumb_path.$id.".".$file_extension;       if(file_exists($tmp_upload_path.$source_name)){       unlink($tmp_upload_path.$source_name); //remove file     }      move_uploaded_file($source_image , $new_source);      $upload_img_arr[] = $new_source;     $upload_img_data = array("upload_img_arr"=>$upload_img_arr);     //$this->session->set_userdata($upload_img_data);      $config['image_library'] = 'gd2';     $config['source_image'] = $new_source;     $config['new_image'] = $new_thumb;     $config['file_permissions'] = 0644;     $config['create_thumb'] = false;     $config['maintain_ratio'] = true;     $config['width'] = 76;     $config['height'] = 76;     $this->load->library('image_lib', $config);     $this->image_lib->initialize();     $this->image_lib->resize();     $this->image_lib->clear();      unset($config);     if (!$this->image_lib->resize()) {       echo $this->image_lib->display_errors();     }      $response = array();     $response['id'] = $id;     $response['thumb_url'] = $new_thumb;     echo json_encode($response);   }    function generaterandomstring($length = 63) {     $characters = '0123456789abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz';     $characterslength = strlen($characters);     $randomstring = '';     ($i = 0; $i < $length; $i++) {         $randomstring .= $characters[rand(0, $characterslength - 1)];     }     return $randomstring; }       function resize($img, $width=0, $height=0){     $config['image_library'] = 'gd2';     $config['source_image'] = "./uploads/tmp/orignals/".$img;     if($width==176){         $config['new_image'] = "./uploads/images/news/smalls/".$img;     }else if($width==360){         $config['new_image'] = "./uploads/images/news/mediums/".$img;     }else if($width==1024){         $config['new_image'] = "./uploads/images/news/large/".$img;     }     echo $config['new_image']."<br>";     $config['file_permissions'] = 0644;     $config['create_thumb'] = false;     $config['maintain_ratio'] = true;     $config['width'] = $width;     $config['height'] = $height;     $this->load->library('image_lib', $config);     $this->image_lib->initialize();     $this->image_lib->resize();     $this->image_lib->clear();      unset($config);      if (!$this->image_lib->resize()) {       echo $this->image_lib->display_errors();     }   }   } 

i figure out:

$this->image_lib->initialize(); 

should have new config every time used as:

$this->image_lib->initialize($config); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -