CodeIgniter Forums
image manipulation problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: image manipulation problem (/thread-37523.html)



image manipulation problem - El Forum - 01-12-2011

[eluser]Richko[/eluser]
Hi, i am trying to resize uploaded image and then make thumb. But when it only resizes doesn't make a thumb.

Code:
<?php

Class Gallery_model extends Model {

    private $gallery_path;

    function Gallery_model() {
        parent::Model();
        $this->gallery_path = realpath(APPPATH . '../public/upload/gallery');
    }

    function do_upload() {
        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png|x-png',
            'upload_path' => $this->gallery_path,
            'max_size' => 2000
        );
        $this->load->library('upload', $config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();

        // resize
        $config = array(
            'image_library' => 'GD2',
            'source_image' => $image_data['full_path'],
            'new_image' => $this->gallery_path . '/resized',
            'maintain_ratio' => TRUE,
            'width' => 800,
            'height' => 600
        );
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
        $this->image_lib->clear();

        // thumb
        $config = array(
            'image_library' => 'GD2',
            'source_image' => $image_data['full_path'],
            'new_image' => $this->gallery_path . '/thumbs',
            'create_thumb' => TRUE,
            'thumb_marker' => '_thumb',
            'maintain_ratio' => TRUE,
            'width' => 100,
            'height' => 100
        );
        $this->load->library('image_lib', $config);
        $this->image_lib->resize();
    }

}

?>



image manipulation problem - El Forum - 01-12-2011

[eluser]Richko[/eluser]
Solved.
$this->load->library('image_lib', $config);
$this->image_lib->initialize($config); // Just added this line. Magic? Smile

Code:
<?php
Class Gallery_model extends Model {

    private $gallery_path;

    function Gallery_model() {
        parent::Model();
        $this->gallery_path = realpath(APPPATH . '../public/upload/gallery');
    }

    function do_upload() {
        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png|x-png',
            'upload_path' => $this->gallery_path,
            'max_size' => 2000
        );
        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        $this->upload->do_upload();
        $image_data = $this->upload->data();

        // resize
        $config = array(
            'image_library' => 'GD2',
            'source_image' => $image_data['full_path'],
            'new_image' => $this->gallery_path . '/resized',
            'maintain_ratio' => TRUE,
            'width' => 800,
            'height' => 600
        );
        $this->load->library('image_lib', $config);
        $this->image_lib->initialize($config);
        $this->image_lib->resize();
        $this->image_lib->clear();

        // thumb
        $config = array(
            'image_library' => 'GD2',
            'source_image' => $image_data['full_path'],
            'new_image' => $this->gallery_path . '/thumbs',
            'create_thumb' => TRUE,
            'thumb_marker' => '_thumb',
            'maintain_ratio' => TRUE,
            'width' => 100,
            'height' => 100
        );
        $this->load->library('image_lib', $config);
        $this->image_lib->initialize($config);
        $this->image_lib->resize();
    }

}

?>



image manipulation problem - El Forum - 03-22-2011

[eluser]Zeff[/eluser]
Hi Richko, indeed! Had the same problem, an extra 'initialize' of the config parameters did it. Thanks!