Welcome Guest, Not a member yet? Register   Sign In
Image Manipulation Class causing strange blackness (pics included)
#1

[eluser]Gwarrior[/eluser]
As the title says, when I resize an uploaded file, it is making the actual image appear in the corner and the rest of the image black. So in essence, it works, but for some reason not fully correctly. It seems as if it is keeping the pictures default ratio, even though I have configed that out. To understand what I mean, please look at the images on this page.

Below is the function in my class that does the upload.
Code:
// upload a picture, plus resize the image provided into a thumbnail
    function do_upload_plus($filename) {
        $CI =& get_instance();
        
        // set config
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size']    = '500';
        $config['max_width']  = '500';
        $config['max_height']  = '500';
        $CI->load->library('upload', $config);
        
        // try to do the actual upload
        if ( ! $CI->upload->do_upload($filename)){
            
            // if it doesn't work, return errors
            return $CI->upload->display_errors();
            
        // if it works
        } else {
            
            // do upload, then get the filename and return it
            $CI->upload->do_upload($filename);
            $hold = $CI->upload->data();
            $return['picture'] = $hold['file_name'];
            $src_img = $hold['full_path'];
            
            
            // then resize that image into a thumbnail
            $iconfig['width']  = '140';
            $iconfig['height']  = '105';
            $iconfig['source_image'] = $src_img;
            $iconfig['maintain_ratio'] = FALSE;
            $CI->load->library('image_lib', $iconfig);
            $CI->image_lib->resize();
            if (! $CI->image_lib->resize()) {
                $return['resize_error'] = $CI->image_lib->display_errors();    
            }
        }
        return $return;
    }

Any help? Thanks!
#2

[eluser]Gwarrior[/eluser]
But now, without any code changes, it magically works.

Hmph. Thanks anyway!
#3

[eluser]BrianDHall[/eluser]
I think you'll find the problem is with transparent images. GD/GD2, the default library CI uses for image manipulation, doesn't properly support transparent GIF and PNG files, so if you resize them they end up with a black background. There was a fix posted here somewhere, I just can't recall the link...
#4

[eluser]BrianDHall[/eluser]
Found it! Fix for transparent image resizing




Theme © iAndrew 2016 - Forum software by © MyBB