Welcome Guest, Not a member yet? Register   Sign In
Crop image not working
#1

[eluser]morph london[/eluser]
I have this script working on my site, the thumb is created to size but the crop is not applied, any suggestions would be great:

Code:
function image()
    {
        $folder = "assets/images/content/".$this->uri->segment(3)."/".$this->uri->segment(4)."/";
        
        if(!file_exists($folder)) mkdir($folder, 0777);
        
        move_uploaded_file($_FILES['Filedata']['tmp_name'], $folder."main.jpg");
        
        if(file_exists($folder."main.jpg"))
        {
            $this->load->library('image_lib');
            chmod($folder."main.jpg", 0777);
        
            // RESIZE
            $config['image_library'] = 'GD2';
            $config['source_image'] = $folder."main.jpg";
            $config['maintain_ratio'] = FALSE;
            $config['width'] = 490;
            $config['height'] = 234;
        
            $this->image_lib->clear();
            $this->image_lib->initialize($config);
            $this->image_lib->resize();
            
            // THUMB
            $config['image_library'] = 'GD2';
            $config['source_image'] = $folder."main.jpg";
            $config['new_image'] = $folder."thumb.jpg";
            $config['maintain_ratio'] = TRUE;
            $config['height'] = 118;
            $config['width'] = 247;

            $this->image_lib->clear();
            $this->image_lib->initialize($config);
            $this->image_lib->resize();
            
            
            //CROP THUMB
            //$config['image_library'] = 'GD2';
            $config['source_image'] = $folder."thumb.jpg";
            $config['x_axis'] = '109';
            $config['y_axis'] = '118';
            
            $this->image_lib->clear();
            $this->image_lib->initialize($config);
            $this->image_lib->crop();
            chmod($folder."thumb.jpg", 0777);
        }
    }
#2

[eluser]JimmyJ[/eluser]
OMG! How could i be so dumb!!! Can't believe it Sad

Ok, now I got

Code:
<?php

//echo $_SERVER['DOCUMENT_ROOT'];
//print_r($_POST);

    mysql_query("INSERT INTO gallery (pageID, imageTitle, imageDesc) VALUES ('$_POST[pageID]', '$_POST[imageTitle]', '$_POST[imageDesc]')");    
    $imageid = mysql_insert_id();
    
    
    $folder = $_SERVER['DOCUMENT_ROOT'] . 'userFiles/gallery/large/';
    $thumbFolder = $_SERVER['DOCUMENT_ROOT'] . 'userFiles/gallery/thumbs/';
    
        //if(!empty($_FILES['userfile'])){ echo '<p style="color:green">file detection successful</p>'; }
        //else { echo '<p style="color:red">file failed to upload</p>'; }

    move_uploaded_file($_FILES['userfile']['tmp_name'], $folder.$imageid.".jpg");    
    
    if(file_exists($folder.$imageid.".jpg"))
       {
    $this->load->library('image_lib');

    
    // RESIZE
    $config[] = 'GD2';
    $config['source_image'] = $folder.$imageid.".jpg";
    $config['maintain_ratio'] = TRUE;
    $config['width'] = 500;
    $config['height'] = 400;
    
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    
    // THUMB
    $config[] = 'GD2';
    $config['source_image'] = $folder.$imageid.".jpg";
    $config['new_image'] = $thumbFolder.$imageid.".jpg";
    $config['maintain_ratio'] = TRUE;
    $config['height'] = 118;
    $config['width'] = 247;
    
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->resize();
    chmod($folder.$imageid."jpg", 0777);
    
    //CROP THUMB
    $config[] = 'GD2';
    $config['source_image'] = $thumbFolder.$imageid.".jpg";
    $config['x_axis'] = 109;
    $config['y_axis'] = 11;
    
    $this->image_lib->clear();
    $this->image_lib->initialize($config);
    $this->image_lib->crop();
}

die("<p>End</p>");
header("location: /admin/pages/modify/$_POST[pageID]");
?&gt;

But i'm getting an error

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$image_lib

Filename: pages/add-gallery.php

Line Number: 30

Fatal error: Call to a member function clear() on a non-object in D:\Websites\server\www\core\application\views\admin\pages\add-gallery.php on line 30

Any ideas?
#3

[eluser]dsheetz[/eluser]
Gotta love the responsiveness of the dev team here.




Theme © iAndrew 2016 - Forum software by © MyBB