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
        }
    }