Welcome Guest, Not a member yet? Register   Sign In
Problem resizing one original image two times
#1

[eluser]Unknown[/eluser]
Hi I've the following problem

I upload one image in the directory ./images/originals

Then I want to resize this image to a compacter format. Therfore i resize it and create with the $config['new_image'] attribute a compact version in ./images/compact

After this i resize the original image to create a thumbnail version. Therfore i resize it with the $config['new_image'] attribute to create the thumbnail in ./images/thumbnails

The problem is that after the upload the thumbnail is created but the compact version is not. I don't know why. Maybe you can help me?

Here is the code

Code:
function save() {
            
        $config ['upload_path'] = './images/originals/';
        $config ['allowed_types'] = 'gif|jpg|png|jpeg';
        $config ['max_size'] = '2048';
        $config ['max_width'] = '0';
        $config ['max_height'] = '0';
        
        $this->load->library ( 'upload', $config );
            
        if ($this->upload->do_upload ()) {
            $data = array ('upload_data' => $this->upload->data () );
            $this->create_thumb( $data ['upload_data'] ['file_name'] );  // Thumbnail creation
            $this->create_compact( $data ['upload_data'] ['file_name'] ); // compact version creation
        } else {
            $error = array ('error' => $this->upload->display_errors () );
            $this->load->view ( 'upload_form', $error );
        }
    }

    function create_thumb($filename) {
    
        if(!is_dir("./images/thumbnails/".$this->user))
            mkdir("./images/thumbnails/".$this->user, 0777);
            
        $config ['image_library'] = 'GD';
        $config ['thumb_marker'] = '';
        $config ['source_image'] = './images/originals/' . $filename;
        $config ['new_image'] = './images/thumbnails/thumb_' . $filename;
        $config ['create_thumb'] = TRUE;
        $config ['maintain_ratio'] = TRUE;
        $config ['width'] = 100;
        $config ['height'] = 100;
        
        $this->load->library ( 'image_lib', $config );
        
        if ($this->image_lib->resize ()) {
            $data = array ('image' => $config ['new_image'] );
        } else {
            $data = array ('error' => $this->image_lib->display_errors () );
        }
        $this->load->view ( 'images_show', $data );
    }
    
    function create_compact($filename) {
        $config ['image_library'] = 'GD';
        $config ['quality'] = '80%';
        $config ['source_image'] = './images/originals/' . $filename;
        $config ['new_image'] = './images/compact/c' . $filename;
        $config ['maintain_ratio'] = TRUE;
        $config ['width'] = 800;
        $config ['height'] = 600;
        
        $this->load->library ( 'image_lib', $config );
        
        $this->image_lib->resize ();
    }
#2

[eluser]wiredesignz[/eluser]
The image library needs to be clear()'d and re initialize()'d for each call, the second call to load the library is ignored by CI (the class is already loaded) so the constructor is not run with the second config settings.
#3

[eluser]Unknown[/eluser]
thank you

now it worked the way i want to!
#4

[eluser]gunter[/eluser]
every 3 days someone with this problem... It would be time to change the first example in the userguide...
#5

[eluser]jaume[/eluser]
that's right gunter, maybe this would be the solution! Wink
#6

[eluser]Sumon[/eluser]
Frinds,

Her is my code:
Code:
$config['image_library'] = 'GD2';
$config['source_image'] = './gallery/image_gallery/tmp_photos/'.$MainFileName;
//$config ['quality'] = '80%';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 600;
$config['height'] = 450;
$config['new_image'] = './gallery/image_gallery/original_photo/'.$MainFileName;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$this->image_lib->clear();

// Resize $MainFileName to SmallPicture (100X100) into thumbnail
$config['image_library'] = 'GD';
$config['source_image'] = './gallery/image_gallery/tmp_photos/'.$MainFileName;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 110;
$config['height'] = 110;
$config['new_image'] = './gallery/image_gallery/thumbnail/'.$MainFileName;
$this->load->library('image_lib', $config);
$this->image_lib->resize();

First resize is working but not second one. I feel this line is incorrect $this->image_lib->clear(); please let me know correct one.
#7

[eluser]wiredesignz[/eluser]
The image library needs to be re initialize()’d for each call, the second call to load the library is ignored because the class is already loaded.
#8

[eluser]Sumon[/eluser]
who shall i do that? please let me know ...
#9

[eluser]wiredesignz[/eluser]
The user guide is very vague about re-using the image library, but if you read carefully you see this.
Code:
$this->image_lib->initialize($config);
#10

[eluser]Sumon[/eluser]
Thanks a lot..... Smile




Theme © iAndrew 2016 - Forum software by © MyBB