Sha256: ba61a8761c73c60dc156b4f700710db0eaa4f9764b8bc0404b3c5cf52cc5e943
Contents?: true
Size: 1003 Bytes
Versions: 3
Compression:
Stored size: 1003 Bytes
Contents
import os from PIL import ImageFont def get_width_for_font_size(draw, font_type, font_size, label): font = ImageFont.truetype(font_type, font_size) return draw.textsize(label, font=font) def get_optimal_font_size(draw, font_type, max_width, max_height, label, min_font_size, font_size = 100): """ Find the maximum font_size given a label to display in a max_width, using a font_type """ if font_size < min_font_size: return None font = ImageFont.truetype(font_type, font_size) label_width, label_height = draw.textsize(label, font=font) if label_width < max_width and label_height < max_height: return font_size else: return get_optimal_font_size(draw, font_type, max_width, max_height, label, min_font_size, font_size -1) def get_font(font_name): font_path = os.path.join(os.path.dirname(__file__), 'pilfonts', font_name) if os.path.isfile(font_path): return font_path else: raise Exception("Font %s not found" % font_name)
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
nagios-herald-0.0.4 | lib/stackbars/chart_utils.py |
nagios-herald-0.0.3 | lib/stackbars/chart_utils.py |
nagios-herald-0.0.2 | lib/stackbars/chart_utils.py |