Welcome Guest, Not a member yet? Register   Sign In
URGENT: Image upload & resize issues
#1

[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:
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.


Messages In This Thread
URGENT: Image upload & resize issues - by El Forum - 05-13-2008, 04:35 PM
URGENT: Image upload & resize issues - by El Forum - 05-14-2008, 08:15 AM
URGENT: Image upload & resize issues - by El Forum - 05-14-2008, 11:35 AM
URGENT: Image upload & resize issues - by El Forum - 05-14-2008, 11:49 AM
URGENT: Image upload & resize issues - by El Forum - 05-14-2008, 12:37 PM
URGENT: Image upload & resize issues - by El Forum - 05-14-2008, 12:51 PM
URGENT: Image upload & resize issues - by El Forum - 05-14-2008, 12:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB