05-13-2008, 04:35 PM
[eluser]BrandonDurham[/eluser]
For some reason the below function fails when the image is only slightly taller than it is wide. I think it's breaking when it gets to the crop bit:
Here's the error I get:
Here's a sample image that makes it break: http://www.amillionthingstodo.com/ci/Hys...gogram.JPG
If I make that image just 100px wder or taller it works fine. Any ideas? This is kind of urgent.
I appreciate any help I can get.
For some reason the below function fails when the image is only slightly taller than it is wide. I think it's breaking when it gets to the crop bit:
Code:
function uploadHeaderImage($directory) {
$CI =& get_instance();
// Upload image
$config['upload_path'] = $CI->config->item('live_server_path') . 'mbg/images/' . $directory . '/originals/';
$config['allowed_types'] = 'jpg';
$config['max_size'] = '6000';
$CI->load->library('upload', $config);
if (!$CI->upload->do_upload("cover"))
{
echo "Original: ".$CI->upload->display_errors();
return false;
}
// Create various images sizes
$CI->load->library('image_lib');
$data = $CI->upload->data();
$image_path = $data['full_path'];
$extension = $data['file_ext'];
$config['image_library'] = 'GD2';
$config['source_image'] = $image_path;
$config['maintain_ratio'] = TRUE;
// Resize image
$config['new_image'] = $CI->config->item('live_server_path') . 'mbg/images/' . $directory . '/' . $data['raw_name'] . $extension;
$config['width'] = 590;
$config['height'] = 2000;
$CI->image_lib->initialize($config);
if (!$CI->image_lib->resize()) {
echo $CI->image_lib->display_errors();
return false;
}
// Crop and make thumb
$img_width = $data['image_width'];
$img_height = $data['image_height'];
$crop_ratio = ($img_width >= $img_height) ? $img_height/150 : $img_width/130;
$config['new_image'] = $CI->config->item('live_server_path') . 'mbg/images/' . $directory . '/email/' . $data['raw_name'] . $extension;
$config['width'] = 130 * $crop_ratio;
$config['height'] = 150 * $crop_ratio;
$config['x_axis'] = ($img_width - $config['width'])/2;
$config['y_axis'] = ($img_height - $config['height'])/2;
$config['maintain_ratio'] = FALSE;
$CI->image_lib->initialize($config);
if (!$CI->image_lib->crop()) {
echo $CI->image_lib->display_errors();
return false;
}
$CI->image_lib->clear();
$config['image_library'] = 'GD2';
$config['source_image'] = $CI->config->item('live_server_path') . 'mbg/images/' . $directory . '/email/' . $data['raw_name'] . $extension;
$config['width'] = 130;
$config['height'] = 150;
$CI->image_lib->initialize($config);
if (!$CI->image_lib->resize()) {
echo $CI->image_lib->display_errors();
return false;
}
return $data['raw_name'] . $extension;
}
Here's the error I get:
Quote:The path to the image is not correct
Your server does not support the GD function required to process this type of image.
Here's a sample image that makes it break: http://www.amillionthingstodo.com/ci/Hys...gogram.JPG
If I make that image just 100px wder or taller it works fine. Any ideas? This is kind of urgent.
I appreciate any help I can get.