Welcome Guest, Not a member yet? Register   Sign In
create more than 2 thumbnails using ci
#1

[eluser]dsi[/eluser]
hi, i am trying to create 1 main uploaded file and 2 other different size thumbnails. i have successfully created the first thumbnail but couldnot create 2nd thumbnail, can anyone help.

i have created a function for main upload file, it will call 2nd function for 1st thumbnail creation. I tried to call 3rd function for 2nd thumbnail generation but it doesnot work. I tried calling from both functions.

any suggestions?

here is my file upload class
Code:
class Upload_model extends Model{
    function do_upload(){

        $this->load->library('upload');
        if ($this->upload->do_upload()){
            $file_info=$this->upload->data();
            $q=$this->_create_thumbnail($file_info['file_name']);
            $r=$this->_create_thumbnail1($file_info['file_name']);
            if($r){
                $file['file_name']=$file_info['raw_name'];
                $file['file_ext']=$file_info['file_ext'];
                return $file;
            }
        }

    }
    
    function _create_thumbnail($filename){
        $config['image_library'] = 'gd2';
        $config['source_image'] = 'upload/'.$filename;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['new_image']='upload/thumb/';
        $config['width'] = 154;
        $config['height'] = 121;
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
    }
    
    function _create_thumbnail1($filename){
        $config['image_library'] = 'gd2';
        $config['source_image'] = 'upload/'.$filename;
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = TRUE;
        $config['new_image']='upload/thumb/featured/';
        $config['width'] = 154;
        $config['height'] = 121;
        $this->load->library('image_lib', $config);
        if($this->image_lib->resize()) return true;
    }
}
#2

[eluser]dsi[/eluser]
and there's another problem, when i return false in 3rd function it still uploads the file, but not the thumbnails.

can anyone help?
#3

[eluser]cahva[/eluser]
Does it create the thumbnails if you use this:
Code:
function _create_thumbnails($filename)
{
    $config['image_library'] = 'gd2';
    $config['source_image'] = 'upload/'.$filename;
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['new_image']='upload/thumb/';
    $config['width'] = 154;
    $config['height'] = 121;
    $this->load->library('image_lib', $config);
    $this->image_lib->resize();

    $this->image_lib->clear(); // This is used normally if you do images in a loop

    $config['image_library'] = 'gd2';
    $config['source_image'] = 'upload/'.$filename;
    $config['create_thumb'] = TRUE;
    $config['maintain_ratio'] = TRUE;
    $config['new_image']='upload/thumb/featured/';
    $config['width'] = 154;
    $config['height'] = 121;
    $this->load->library('image_lib', $config);
    $this->image_lib->resize();
}
#4

[eluser]391[/eluser]
<?php
class Img extends Controller
{
public function __construct()
{
parent::Controller();
$this->load->library("image_lib");
$this->load->helper("form");
}
public function index()
{
$this->load->view('image',array('error'=>''));
}
public function do_upload()
{
$config['upload_path'] = './images/'; //cung cap voi system
$config['allowed_types'] = 'gif|jpg|png'; //the loai upload vao
$config['max_size'] = '2040';
$config['remove_spaces'] = true;
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload',$config);
if ( ! $this->upload->do_upload('image'))
{
$error = array('error' => $this->upload->display_errors());

$this->load->view("v_image", $error);
}
else
{
$image = array('upload_data' => $this->upload->data());
$thumbnail='./images/'."thumb_".$image['upload_data']['file_name'];

$featured='./images/'.'/featured/'."thumb_".'$image['upload_data']['file_name'];
$up['image_library'] = 'gd2';
$up['source_image'] = './images/'.$image['upload_data']['file_name'];
$up['create_thumb'] = TRUE;
$up['maintain_ratio'] = TRUE;
$up['width'] = 200;
$up['height'] = 121;
$this->image_lib->initialize($up);
$this->image_lib->resize();

//echo "Upload ok";
}
}
}
?>


//U can try it...
#5

[eluser]dsi[/eluser]
to 391:
u have set 2 variables with their filenames and location but how are those images actually being created? will they be automatically created or r u missing something??
#6

[eluser]391[/eluser]
i don't understand your question.If u difficult about upload image and thumbnail..U can send i. your email.i'll send code u...hope help u..my mail: [email protected]
#7

[eluser]Satlavida[/eluser]
[quote author="391" date="1272464489"]<?php
class Img extends Controller
{
public function __construct()
{
parent::Controller();
$this->load->library("image_lib");
$this->load->helper("form");
}
public function index()
{
$this->load->view('image',array('error'=>''));
}
public function do_upload()
{
$config['upload_path'] = './images/'; //cung cap voi system
$config['allowed_types'] = 'gif|jpg|png'; //the loai upload vao
$config['max_size'] = '2040';
$config['remove_spaces'] = true;
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload',$config);
if ( ! $this->upload->do_upload('image'))
{
$error = array('error' => $this->upload->display_errors());

$this->load->view("v_image", $error);
}
else
{
$image = array('upload_data' => $this->upload->data());
$thumbnail='./images/'."thumb_".$image['upload_data']['file_name'];

$featured='./images/'.'/featured/'."thumb_".'$image['upload_data']['file_name'];
$up['image_library'] = 'gd2';
$up['source_image'] = './images/'.$image['upload_data']['file_name'];
$up['create_thumb'] = TRUE;
$up['maintain_ratio'] = TRUE;
$up['width'] = 200;
$up['height'] = 121;
$this->image_lib->initialize($up);
$this->image_lib->resize();

//echo "Upload ok";
}
}
}
?>


//U can try it...[/quote]


Thanks...




Theme © iAndrew 2016 - Forum software by © MyBB