Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all articles
Browse latest Browse all 14343

Problem With Image Resizing

$
0
0
Hello to All Members,

I have a problem in image resizing. I have a function name as do_resize(). it gets 4 parameters and return the name of the the new resized file. the code of this function is given below.
PHP Code:
public function do_resize($source_file$target_folder$height 128$width 128)
 
   {
 
       $filename $source_file;
 
       $temp_data explode('/',$filename);
 
       $new_filename end($temp_data);

 
       $temp_data explode('.'$new_filename);
 
       $ext end($temp_data);
 
       $new_filename $temp_data[0] . $width .'-'$height .'.'$ext;
 
       $source_path $filename;

 
       $folder_path '';
 
       $temp_folder explode('/',$target_folder);

 
       foreach ($temp_folder as $folder) {
 
           $folder_path .=$folder '/';
 
           if (!file_exists($folder_path)) {
 
               mkdir($folder_path);
 
           }
 
       }
 
       $target_path $target_folder;

 
       if(isset($config_manip)){
 
           unset($config_manip);
 
       }

 
       $config_manip = array(
 
           'image_library'     => 'gd2',
 
           'source_image'      => $source_path,
 
           'maintain_ratio'    => FALSE,
 
           'new_image'         => $target_path,
 
           'create_thumb'      => TRUE,
 
           'thumb_marker'      =>  $width '-'$height,
 
           'width'             => $width,
 
           'height'            => $height
        
);
 
       
        $this
->load->library('image_lib'$config_manip);
 
       if (!$this->image_lib->resize()) {
 
           echo $this->image_lib->display_errors();
 
           echo "<br>";
 
           echo $config_manip['source_image'];
 
       }
 
       // clear //
 
       $this->image_lib->clear();
 
       return $folder_path $new_filename;
 
   

This function only work for one time. I'm calling this function from a loop to resize multiple images. the code of the loop is like this.
PHP Code:
foreach ($data['distributors'] as $key => $item){
 
    $target_folder 'uploads/images/cache/distributor/profile-image';
 
    $name $this->do_resize($item['profile_image'], $target_folder128,128);
 
    $data['distributors'][$key]['profile_image'] =  base_url($name);
 
    $data['distributors'][$key]['added_date'] =  date($this->dateFormatstrtotime($item['added_date']));



I'm expecting from this code is that. When I starts the loop, at each attrition of the loop it takes the profile-image path and pass to the do_resize() function which will resize the image and store it in a target folder. But it works only for first attrition of the loop. and remaining profile-images are not resized. 

Any one can help me to solve this issue. Thanks

Viewing all articles
Browse latest Browse all 14343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>