CodeIgniter Forums
Get image width of uploaded file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Get image width of uploaded file (/showthread.php?tid=27342)



Get image width of uploaded file - El Forum - 02-08-2010

[eluser]yabune[/eluser]
Hi,

I'm uploading an image with CI File Uploading class ( a jpg image) and then I'm trying to get the image width with $this->upload->data() but image_width is not recognized...

Here is the code:
Code:
function upload($tag, $w, $h)
    {
        if ( ! empty($_FILES[$tag]['name'] ) )
        {
            $CI =& get_instance();
            $config['upload_path'] = 'assets/uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '2000';
            $config['max_width']  = $this->max_width;
            $config['max_height']  = $this->max_height;
            $CI->upload->initialize($config);
            if ( ! $CI->upload->do_upload($tag))
            {
                $this->error = $CI->upload->display_errors();
                return '';
            }    
            else
            {
                $uploaded_file = $CI->upload->data();

                $config['source_image']    = $uploaded_file['full_path'];
                $config['maintain_ratio'] = TRUE;
                if($uploaded_file['image_width'] > $w || $uploaded_file['image_heigth'] > $h) {
                    $config['width']     = $w;
                    $config['height']    = $h;
                }
                $CI->image_lib->initialize($config);
                if ( ! $CI->image_lib->resize())
                {
                    $this->error = $CI->image_lib->display_errors();
                    return '';
                }

                return 'assets/uploads/'.$uploaded_file['file_name'];
            }
        }
        else
        {
            return '';
        }
    }

The strange thing is that other image parameters like is_image and image_type are ok.
And if I serialize the $uploaded_file array data, I can see there the image_width and image_height attributes... Don't understand why it fails when I try to access them...

Thank you!


Get image width of uploaded file - El Forum - 02-08-2010

[eluser]danmontgomery[/eluser]
Code:
$uploaded_file['image_heigth']