[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):
?>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="userfile" size="20" />
<input type="submit" name="upload_image" value="upload" />
<?php
if($has_photo != false):
?>
<input type="submit" name="delete_image" value="delete" />
<?php
endif;
?>
</form>
<?php
endif;
if($upload_success === true) echo 'Success!';
?>
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
Thanks guys!
Tom