• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with image manipulation (resizing)

#1
[eluser]tommizzle[/eluser]
Hi all,

I'm currently having a problem with resizing an image using CI's image manipulation class. Here is my controller:

Code:
<?php

class Photo extends Controller {
    
    function _remap($username)
    {    
        
        $data = array();
        
        $this->load->helper('file');
        $this->load->library('image_lib');
        
        $data['userid'] = $this->Autoload_model->get_userid_from_username($username);
        $data['upload_success'] = false;
        $data['is_my_profile'] = false;
        
        if($this->input->post('upload_image')):
            
            $upload_image['file_name'] = $data['userid'];
            $upload_image['upload_path'] = './images/profile/';
            $upload_image['allowed_types'] = 'gif|jpg|png';
            $upload_image['max_width']  = '1024';
            $upload_image['max_height']  = '768';
            $upload_image['overwrite']  = TRUE;
            
            $this->load->library('upload', $upload_image);
        
            if ( ! $this->upload->do_upload()):
                $data['error'] = array('error' => $this->upload->display_errors());
            else:
                $data['upload_success'] = true;
            endif;
            
            $config['image_library'] = 'gd2';
            $config['source_image'] = './images/profile/' . $data['userid'] . '.jpg';
            $config['new_image'] = './images/profile/new_image.jpg';
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 50;
            $config['height'] = 50;
            
            $this->load->library('image_lib', $config);
            
            if ( ! $this->image_lib->resize()):
                echo $this->image_lib->display_errors();
            else:
                echo 'Resize Success';
            endif;
            
        endif;
    
        
        
        if($this->input->post('delete_image')):
            unlink('./images/profile/' . $data['userid'] . '.jpg');
        endif;
        
        
        $data['has_photo'] = read_file('./images/profile/' . $data['userid'] . '.jpg');
        
        if($this->authlib->getUserName() == $username) $data['is_my_profile'] = true;
            
        $this->load->view('photo',$data);
    }

}
    
?>

and my view:
Code:
<?php
if(isset($error)) echo $error;

if($has_photo != false):
        echo '<img src="/images/profile/' . $userid . '.jpg" alt="My Profile Image" />';
else:
        echo '<img src="/images/profile/placeholder.png" alt="My Profile Image" />';
endif;

if($is_my_profile === true):
?&gt;
    &lt;form action="" method="post" enctype="multipart/form-data"&gt;
        &lt;input type="file" name="userfile" size="20" /&gt;
        &lt;input type="submit" name="upload_image" value="upload" /&gt;
        &lt;?php
        if($has_photo != false):
        ?&gt;
            &lt;input type="submit" name="delete_image" value="delete" /&gt;
        &lt;?php
        endif;
        ?&gt;
        
        
    &lt;/form&gt;
&lt;?php
endif;

if($upload_success === true) echo 'Success!';
?&gt;

The image is uploading, and then I'm even getting 'Resize Success', but it's not resizing or creating a new thumb in my chosen dir. I tried the normal 'GD' library too, and that didn't work either.

Has anybody got any ideas what's going wrong here? Any help would be appreciated Smile

Thanks guys!

Tom

#2
[eluser]hugle[/eluser]
hm...
I've been using this lib a while ago with no problems...
Is the directory you are writing thumb writeable?

echo the $config['source_image'];

what does it show?

#3
[eluser]tommizzle[/eluser]
Hi hugle,

source_image shows: ./images/profile/11.jpg (Correct path to my image, not sure about the dot though?)

The directory and the files in it are 777'd

Thanks,

Tom

Edit: Just checked my log, and I'm getting this error:
Code:
ERROR - 2009-11-16 04:23:30 --&gt; The session cookie data did not match what was expected. This could be a possible hacking attempt.
Not sure if it's related?

#4
[eluser]tommizzle[/eluser]
Solved the problem:

There is an error in the documentation on: http://ellislab.com/codeigniter/user-gui...e_lib.html

Quote:$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;

$this->load->library('image_lib', $config); should be $this->image_lib->initialize($config);

$this->image_lib->resize();

Pretty frustrating stuff. Especially as I've spent ~2 days on it :/

#5
[eluser]hugle[/eluser]
[quote author="tommizzle" date="1258389238"]Solved the problem:

There is an error in the documentation on: http://ellislab.com/codeigniter/user-gui...e_lib.html

Quote:$config['image_library'] = 'gd2';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 75;
$config['height'] = 50;

$this->load->library('image_lib', $config); should be $this->image_lib->initialize($config);

$this->image_lib->resize();

Pretty frustrating stuff. Especially as I've spent ~2 days on it :/[/quote]


bah... so bad Sad
sometimes it's good to leave of the pc for 20 minutes, and come back and start from the beginning, but not searching for errors...
sometimes happen!Smile))

#6
[eluser]Unknown[/eluser]
aw snap. just spent 3 hours on this same one. i really could have used the fixed docs.

#7
[eluser]stef25[/eluser]
Same here, documentation really needs to be fixed.

#8
[eluser]Craig300[/eluser]
There isn't really a problem with the documentation it all depends if you have already initialised the library already in the file. If you have, then you just need to initialise it with the array values you pass to it. If you haven't initialised the library, then you can do both at the same time by calling $this->load->library('image_lib', $config);

#9
[eluser]stef25[/eluser]
That's true, my bad. It's just that in the docs it first says

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

and then right below that again

Code:
$this->load->library('image_lib', $config);

That's what's confusing ...

#10
[eluser]Craig300[/eluser]
That got me for a while as well, maybe it could be a bit clearer but once you see whats happening, it kind of makes sense Smile

Glad I could help Smile


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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