Welcome Guest, Not a member yet? Register   Sign In
getting image dimensions
#2

[eluser]sophistry[/eluser]
Here you go... it's your birthday today so I went to the PHP site and I searched on get image size and, what do you know? I found a function called getimagesize(). pretty cool, huh?

http://us2.php.net/manual/en/function.getimagesize.php

good luck in your future PHP manual searches. please be sure to share your learnings with us!

As you so kindly requested, I also looked in the CI codebase for you and found that the Image Library does indeed have a function (undocumented) that can get you the data too. But, you probably don't want to rely on undocumented features... they might change.

Code:
// --------------------------------------------------------------------
    
    /**
     * Get image properties
     *
     * A helper function that gets info about the file
     *
     * @access    public
     * @param    string
     * @return    mixed
     */            
    function get_image_properties($path = '', $return = FALSE)
    {
        // For now we require GD but we should
        // find a way to determine this using IM or NetPBM
        
        if ($path == '')
            $path = $this->full_src_path;
                
        if ( ! file_exists($path))
        {
            $this->set_error('imglib_invalid_path');        
            return FALSE;                
        }
        
        $vals = @getimagesize($path);
        
        $types = array(1 => 'gif', 2 => 'jpeg', 3 => 'png');
        
        $mime = (isset($types[$vals['2']])) ? 'image/'.$types[$vals['2']] : 'image/jpg';
                
        if ($return == TRUE)
        {
            $v['width']            = $vals['0'];
            $v['height']        = $vals['1'];
            $v['image_type']    = $vals['2'];
            $v['size_str']        = $vals['3'];
            $v['mime_type']        = $mime;
            
            return $v;
        }
        
        $this->orig_width    = $vals['0'];
        $this->orig_height    = $vals['1'];
        $this->image_type    = $vals['2'];
        $this->size_str        = $vals['3'];
        $this->mime_type    = $mime;
        
        return TRUE;
    }

Cheers.


Messages In This Thread
getting image dimensions - by El Forum - 07-02-2007, 03:45 PM
getting image dimensions - by El Forum - 07-02-2007, 08:14 PM
getting image dimensions - by El Forum - 07-03-2007, 04:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB