Welcome Guest, Not a member yet? Register   Sign In
Image Manipulation Class on CI 1.7.2
#1

[eluser]Unknown[/eluser]
Hi,

i have problem with the image manipulation class i have to resize an uploaded image 3 times. I just want to create a main image, a preview image and a small image of an uploaded image.

The problem is after I upload the image, the step creating the main image success. But the second step resize uploaded image to create the preview image is display this message "Your server does not support the GD function required to process this type of image.". So now I ask myself why the first step is still working and is resize the upload image correctly but the following step is failing.

[edit]
Checking for some possible problems:

File right, the upload file has 777 after upload, also I try $CI = &get;_instance(); and initialise image lib in the second step with $CI, I also try to do step with the file which is created by step 1. In all cases I got the same error message.
[/edit]

Here is the code:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Upload_file extends Model
{
    private $_error;
    private $_error_start;
    private $_error_end;
    
    public $_file;
    
    function Upload_file()
    {
        parent::Model();
        
        $this->_error_start = '<p>';
        $this->_error_end = '</p>';
    }
    
    function set_error($str)
    {
        $this->_error = $this->_error_start.$str.$this->_error_end;
    }
    
    function display_error()
    {
        return $this->_error;
    }
    
    function product_image()
    {

        $config['upload_path']   = './files/upload/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']         = '1024';
        $config['encrypt_name']  = TRUE;
        
        $this->load->library('upload', $config);
    
        $upload_file = array();
        if ( ! $this->upload->do_upload())
        {
            $this->set_error($this->upload->display_errors());
            return FALSE;
        }    
        else
        {
            $upload_file = $this->upload->data();
        }
        
        # upload file data
        $file_name = $upload_file['file_name'];
        $full_path = $upload_file['full_path'];
        $raw_name = $upload_file['raw_name'];
        $file_ext = $upload_file['file_ext'];
        
        # creating main image
        $config['image_library'] = 'GD2';
        $config['source_image'] = $full_path;
        $config['new_image'] = './files/shop/images/product_images/';
        $config['width'] = '425';
        $config['height'] = '425';
        
        $this->load->library('image_lib', $config);
        
        $this->image_lib->display_errors('', '');
        
        if(!$this->image_lib->resize())
        {
            #@unlink($upload_file['full_path']);
            $this->set_error('resize main '.$this->image_lib->display_errors());
            return FALSE;
        }
        
        
        # creating preview image
        $this->image_lib->clear();
        $config['image_library'] = 'GD2';
        $config['source_image'] = $full_path;
        $config['new_image'] = './files/shop/images/product_images/'.$raw_name.'_preview'.$file_ext;
        $config['width'] = '225';
        $config['height'] = '225';
        
        $this->load->library('image_lib', $config);
        
        $this->image_lib->display_errors('', '');
            
        if(!$this->image_lib->resize())
        {
            @unlink($upload_file['full_path']);
            @unlink('./files/shop/images/product_images/'.$file_name);
            $this->set_error('resize preview '.$this->image_lib->display_errors());
            return FALSE;
        }
        
        # creating small imager
        $this->image_lib->clear();
        $config['image_library'] = 'GD2';
        $config['source_image'] = $full_path;
        $config['new_image'] = './files/shop/images/product_images/'.$raw_name.'_small'.$file_ext;
        $config['width'] = '111';
        $config['height'] = '111';
        
        $this->load->library('image_lib', $config);
        
        $this->image_lib->display_errors('', '');
        
        if(!$this->image_lib->resize())
        {
            @unlink($upload_file['full_path']);
            @unlink('./files/shop/images/product_images/'.$file_name);
            @unlink('./files/shop/images/product_images/'.$raw_name.'_small'.$file_ext);
            $this->set_error('resize small '.$this->image_lib->display_errors());
            return FALSE;
        }
        
        # delete uploaded image
        @unlink($upload_file['full_path']);
        
        $file_array = array(
            'image_name' => $file_name
        );
        $this->_file = $file_array;
        
        return TRUE;
    }
}

/* End of file upload_file.php */
/* Location: ./application/models/upload_file.php */

If anyone have a suggestion, feel free.

Thanks Mathias
#2

[eluser]Unknown[/eluser]
Solved

look at: Problem with image manipulation (resizing)

The right way to call config paramters for image_lib is:
Code:
$this->load->library('image_lib');

# resize
[Parameter]
$this->image_lib->initialize($config);

# resize next
[Parameter]
$this->image_lib->initialize($config);

Thread could be closed.




Theme © iAndrew 2016 - Forum software by © MyBB