<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Upload_mod extends CI_Model {
function __construct()
{
parent::__construct();
}
function upload_image()
{
$config['upload_path'] = AVATARS_DIR;
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '125';
$config['max_height'] = '125';
$config['overwrite'] = TRUE;
$config['file_name'] = do_hash($this->session->userdata('user_id'));
$this->file_name = do_hash($this->session->userdata('user_id'));
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
return false;
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->create_thumb($this->file_name.'.jpg');
$this->resize_image($this->file_name.'.jpg');
$this->user_mod->update_user_avatar($this->session->userdata('user_id'),$this->file_name.'.jpg');
return true;
}
}
function resize_image($file)
{
$config['image_library'] = 'gd2';
$config['source_image'] = AVATARS_DIR.$file;
$config['maintain_ratio'] = TRUE;
$config['width'] = 125;
$config['height'] = 125;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
unset($config);
$this->session->set_flashdata('resize_error', $this->image_lib->display_errors());
}
function create_thumb($file)
{
$config['image_library'] = 'gd2';
$config['source_image'] = AVATARS_DIR.$file;
$config['maintain_ratio'] = FALSE;
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = "_thumb";
$config['quality'] = '100';
$config['width'] = 55;
$config['height'] = 55;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
unset($config);
$this->session->set_flashdata('thumb_error', $this->image_lib->display_errors());
}
}
?>
If I put $this->create_thumb() before $this->resize_image(), the script creates a thumb but does not resize the image. If I put $this->resize_image() before $this->create_thumb() the script resize the but does not create a thumb. Why?
