public function getImageResizeDefinitionForWidth($width, $fit_in_width = false)
    {
        if (empty($this->image_resize_definitions)) { // no image sizes defined
            return null;
        }

        if ($fit_in_width) {
            foreach ($this->image_resize_definitions as $w => $ird) {
                if ($w > $width && isset($prev_ird)) {
                    return $prev_ird;
                } elseif ($w >= $width) {
                    return $ird; // return smallest possible value even if it is greater than required
                }
                $prev_ird = $ird;
            }
            return $ird; // return greatest available value
        } else {
            foreach ($this->image_resize_definitions as $w => $ird) {
                if ($w >= $width) {
                    return $ird;
                }
            }
            return $ird; // return greatest available value
        }
    }
public function getImageResizeDefinitionForWidth($width, $fit_in_width = false)
    {
        if (empty($this->image_resize_definitions)) { // no image sizes defined
            return null;
        }

        if ($fit_in_width) {
            foreach ($this->image_resize_definitions as $w => $ird) {
                if ($w > $width && isset($prev_ird)) {
                    return $prev_ird;
                } elseif ($w >= $width) {
                    return $ird; // return smallest possible value even if it is greater than required
                }
                $prev_ird = $ird;
            }
            return $ird; // return greatest available value
        } else {
            foreach ($this->image_resize_definitions as $w => $ird) {
                if ($w >= $width) {
                    return $ird;
                }
            }
            return $ird; // return greatest available value
        }
    }
public function getImageResizeDefinitionForWidth ( $ width , $ fit_in_width = false ) { if ( empty ( $ this -> image_resize_definitions ) ) { // no image sizes defined return null ; } if ( $ fit_in_width ) { foreach ( $ this -> image_resize_definitions as $ w => $ ird ) { if ( $ w > $ width && isset ( $ prev_ird ) ) { return $ prev_ird ; } elseif ( $ w >= $ width ) { return $ ird ; // return smallest possible value even if it is greater than required } $ prev_ird = $ ird ; } return $ ird ; // return greatest available value } else { foreach ( $ this -> image_resize_definitions as $ w => $ ird ) { if ( $ w >= $ width ) { return $ ird ; } } return $ ird ; // return greatest available value } }
Get nearest available ImageSizeDefinition for given screen width

@param int $width
@param boolean $fit_in_width If false, returns ImageSizeDefinition greater than width; if true, returns ImageSizeDefinition smaller than width
@return ImageResizeDefinition|null Matching ImageSizeDefinition or NULL if no ImageSizeDefinitions available
Get nearest available ImageSizeDefinition for given screen width