Image resize issues - El Forum - 04-23-2012
[eluser]Matty[/eluser]
I have created a gallery page which allows me to upload images to a gallery but for some reason when I try and do the image resize I just get a white page! I am sure that the issue is when I run the following code but I can't seem to find out what is wrong.
Code: $configresize = array(
'image_library' => 'GD2',
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '/thumbs',
'maintain_ratio' => true,
'width' => 150,
'height' => 150
);
//Initialize the image library for manipulation
$this->load->library('image_lib', $configresize);
if(!$this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
When I run this code I cant even seem to get the errors working and I haven't a clue why, please can someone help. In my experience with CI a blank white page is usually a slight code error like not closing an echo etc, but I can not see where it could be.
My view holds this form
Code: echo '<h3>Add an Image</h3>';
var_dump($this->session->all_userdata());
$hidden = array('form' => 'gallery');
$url = base_url() . uri_string();
echo form_open_multipart($url, '', $hidden);
?>
<p>
<?php echo form_upload('userfile'); ?>
</p>
<p>
<?php echo form_label('Image Description', 'i_description');?>
<?php echo form_textarea('i_description', set_value('i_description', $this->input->post('i_description')));?>
<p>
<?php echo form_submit('upload', 'Upload'); ?>
</p>
<?php
echo form_close();
My controller calls the gallery model function when the upload is sent
Code: function gallery()
{
$data = $this->_user_data();
if($this->input->post('upload')){
$data['upload'] = $this->gallery_model->do_upload();
}
$where = array(
'p_id' => $data['user_profile']->p_id,
'i_gallery' => $this->uri->segment(4)
);
$data['images'] = $this->crud_model->fetch_rows_where('artist_images', $where);
$data['template'] = 'admin/gallery';
$this->load->view('layouts/template', $data);
}
And this is the gallery model function to handle the data
Code: class Gallery_model extends CI_Model {
var $gallery_path;
var $gallery_path_url;
function __construct()
{
parent::__construct();
$this->gallery_path = realpath(APPPATH . '../public/img/uploads');
$this->gallery_path_url = base_url().'public/img/uploads/';
// Load the form validation library
$this->load->library('form_validation');
}
function do_upload()
{
//Set the config options/rules for the uploaded file
$config = array(
'allowed_types' => 'png|jpg|jpeg|gif',
'upload_path' => $this->gallery_path,
'max_size' => 2048
);
//initialize the upload library
$this->load->library('upload', $config);
// See if the upload completes and if not then return an error
if( ! $this->upload->do_upload())
{
$error = $this->upload->display_errors();
return $error;
}
$image_data = $this->upload->data();
//Set the config file for the image library
$configresize = array(
'image_library' => 'GD2',
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '/thumbs',
'maintain_ratio' => true,
'width' => 150,
'height' => 150
);
//Initialize the image library for manipulation
$this->load->library('image_lib', $configresize);
if(!$this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
else
{
$db_config = array(
'p_id' => $this->session->userdata('user_id'),
'artist_id' => $this->session->userdata('user_number'),
'i_gallery' => $this->uri->segment(4),
'i_image' => $this->gallery_path_url . $image_data['file_name'],
'i_thumb' => $this->gallery_path_url . 'thumbs/' . $image_data['file_name']
);
//Insert the data into the database
$this->db->insert('artist_images', $db_config);
return $message;
}
}
function _validate_upload()
{
// Set the rules
$this->form_validation->set_rules('i_description', 'Image Description', 'trim|xss_clean');
// Run and pass the validator
return $this->form_validation->run();
}
}
Image resize issues - El Forum - 04-23-2012
[eluser]astroanu[/eluser]
first try
Code: $this->image_lib->resize();
echo $this->image_lib->display_errors();
it should display smthing weather the resize was successful or not.
Image resize issues - El Forum - 04-23-2012
[eluser]Matty[/eluser]
I tried it but I just get the white page again.
This is my new model function
Code: function do_upload()
{
//Set the config options/rules for the uploaded file
$config = array(
'allowed_types' => 'png|jpg|jpeg|gif',
'upload_path' => $this->gallery_path,
'max_size' => 2048
);
//initialize the upload library
$this->load->library('upload', $config);
// See if the upload completes and if not then return an error
if( ! $this->upload->do_upload())
{
$error = $this->upload->display_errors();
return $error;
}
$image_data = $this->upload->data();
//Set the config file for the image library
$configresize = array(
'image_library' => 'GD2',
'source_image' => $image_data['full_path'],
'new_image' => $this->gallery_path . '/thumbs',
'maintain_ratio' => true,
'width' => 150,
'height' => 150
);
//Initialize the image library for manipulation
$this->load->library('image_lib', $configresize);
$this->image_lib->resize();
echo $this->image_lib->display_errors();
$db_config = array(
'p_id' => $this->session->userdata('user_id'),
'artist_id' => $this->session->userdata('user_number'),
'i_gallery' => $this->uri->segment(4),
'i_image' => $this->gallery_path_url . $image_data['file_name'],
'i_thumb' => $this->gallery_path_url . 'thumbs/' . $image_data['file_name']
);
//Insert the data into the database
$this->db->insert('artist_images', $db_config);
return $message;
}
|