CodeIgniter Forums
Image manipulation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Image manipulation (/showthread.php?tid=70868)



Image manipulation - matchplay - 06-11-2018

I want to resize images using codeigniter image manipulation class. I have tried a few things with no success. I have no errors after running the code below. After the image is uploaded using this code, I manually check to see if the image was resized but they are unchanged from the original size. Can anyone help with this? Is something wrong with the code below? 


 <?php

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Class Edit_main_image extends CI_Controller {
    
     public function __construct()
        {
                parent::__construct();
                $this->load->helper(array('form', 'url'));
                
        }
        
        
            public function do_upload()
        {
                $config['upload_path']          = 'public/uploads/';
                $config['allowed_types']        = 'jpg|png';
                $config['max_size']             = 100;
                $config['max_width']            = 1024;
                $config['max_height']           = 768;
                

        $this->load->library('upload', $config);
        
        

                if ( ! $this->upload->do_upload('mainimg'))
                {
                        $error = array('error' => $this->upload->display_errors());
                        
                        $this->load->view('templates/header');
                        $this->load->view('errorpage');
                        $this->load->view('templates/footer');
                }
                else
                {
                    
             
                         unlink($this->input->post('oldimage'));
                    
       
        $this->load->library('image_lib');
        $this->image_lib->initialize($config);
                    
        $config['image_library'] = 'gd2';
        $config['source_image'] = $config['upload_path'].$this->upload->data('file_name');
        $config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 400;
        $config['height'] = 350;


RE: Image manipulation - InsiteFX - 06-12-2018

For one your using the same config array for both methods, before using the config for the
image lib unset the array then re-initialize it.

SEE The CodeIgniter User's Guide:

Processing an Image

You can use any array name for the config array it doe's not have to be config
just pass the initialize method the right array name.


RE: Image manipulation - matchplay - 06-12-2018

Thanks! Great advice! I made the changes to my code and now it works. Thanks again. See changes to code below.

//START NEW CODE



$newimg['image_library'] = 'gd2';
$newimg['source_image'] = $config['upload_path'].$this->upload->data('file_name');
$newimg['create_thumb'] = FALSE;
$newimg['maintain_ratio'] = FALSE;
$newimg['width'] = 400;
$newimg['height'] = 375;

$this->load->library('image_lib');

$this->image_lib->initialize($newimg);

$this->image_lib->resize();


//END NEW CODE

// NOW IT WORKS!


RE: Image manipulation - InsiteFX - 06-12-2018

Glad you got it to work.