• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
image manipulation problem

#1
[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();
    }

}

?>

#2
[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();
    }

}

?>

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.