Welcome Guest, Not a member yet? Register   Sign In
Image resize does not work!
#1

[eluser]behnampmdg3[/eluser]
Hello;

I use this script below to upload and re size images. Upload works fine but I can't see the re-sized image. In other words it doesn't re size!
I don't get any error messages from echo $this->image_lib->display_errors(); either. It says re sized so it has been successfully re sized. What am I doing wrong?

Thanks


Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Gallery extends CI_Controller
{

public function index()
  {
   $data['title'] = "Gallary Page";
   $data['upload_data']="";
   $this->load->vars($data);
   if($this->input->post('submit'))
    {
     $this->do_upload();
    }
   $this->load_photos();
   $this->view_things();
  }

function do_upload()
  {
   $config['upload_path'] = 'uploads/';
   $this->load->model('add_photo_model');
   $data['new_photo'] = $this->add_photo_model->new_photo_name();
   $config['file_name']  = $data['new_photo'];
   $config['overwrite']  = TRUE;
   $config['allowed_types'] = 'gif|jpg|png';
   $config['max_size'] = '1000';
   $config['max_width']  = '1024';
   $config['max_height']  = '768';
   $this->load->library('upload', $config);
  
   if (!$this->upload->do_upload())
    {
     $data['upload_data'] = $this->upload->display_errors();
     $this->load->vars($data);
    }
   else
    {
     $photo['details']= array('upload_data' => $this->upload->data());
     $this->add_photo_model->add($data['new_photo']);
    
     $data['upload_data'] = "The photo has been uploaded successfully";
     $this->load->vars($data);
     $this->resize($data['new_photo']);
    }
  }

public function resize($photo)
  {
   $config['image_library'] = 'gd2';
   echo $config['source_image'] = $photo;
   $config['create_thumb'] = TRUE;
   $config['maintain_ratio'] = TRUE;
   $config['width'] = 75;
   $config['height'] = 50;
    
   $this->load->library('image_lib', $config);
    
   $this->image_lib->resize();
   if ( ! $this->image_lib->resize())
    {
     echo $this->image_lib->display_errors();
    }
   else
    {
     echo "resized";
    }
  }

public function load_photos()
  {
   $this->load->model('load_photos_model');
   $photos = $this->load_photos_model->check();
   if($photos)
    {
     $photos_num_rows=0;
     foreach($photos as $row)
      {
       $photos_num_rows++;
       $data['photos'][]=$row->photo;
      
      }
     $data['photos_message'] = "There are ".$photos_num_rows." photos uploaded so far";
     $this->load->vars($data);
     return true;
    }
   else
    {
     $data['photos_message'] = "There are no photos uploaded yet!";
     $this->load->vars($data);
    }
  }

  public function view_things()
  {
   $this->load->view('header_view');
   $this->load->view('gallery_view');
   $this->load->view('footer_view');
  }
}
#2

[eluser]LuckyFella73[/eluser]
Try this in the upload part:
Code:
if (!$this->upload->do_upload())
  {
   $data['upload_data'] = $this->upload->display_errors();
   $this->load->vars($data);
  }
  else
  {
   //$photo['details']= array('upload_data' => $this->upload->data());
   $upload_data = $this->upload->data();
  
   $this->add_photo_model->add($data['new_photo']);

   $data['upload_data'] = "The photo has been uploaded successfully";
   $this->load->vars($data);
   //$this->resize($data['new_photo']);
   $this->resize($upload_data['full_path']);
  }

I'm not sure but maybe you better delete the "echo" parts in your
resize section (especially when setting the config values)




Theme © iAndrew 2016 - Forum software by © MyBB