add --tab-artwork-opacity flag (#259)

turn down background opacity to help text show up better against dark
backgrounds
This commit is contained in:
Paul Molodowitch 2019-09-15 20:15:13 -07:00 committed by Peter
parent 43d1e5eae0
commit 3f571cb2af
2 changed files with 28 additions and 1 deletions

View File

@ -6,11 +6,14 @@ import sys
import pkg_resources
from PIL import Image, ImageEnhance
from reportlab.lib.units import cm
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.platypus import Paragraph, XPreformatted
from reportlab.lib.enums import TA_JUSTIFY, TA_CENTER, TA_LEFT
from reportlab.lib.utils import ImageReader
from reportlab.pdfgen import canvas
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.pdfbase.pdfmetrics import stringWidth
@ -1141,6 +1144,8 @@ class DividerDrawer(object):
return w
def drawTab(self, item, wrapper="no", backside=False):
from io import BytesIO
card = item.card
# Skip blank cards
if card.isBlank():
@ -1190,8 +1195,22 @@ class DividerDrawer(object):
# draw banner
img = card.getType().getTabImageFile()
if not self.options.no_tab_artwork and img:
imgToDraw = DividerDrawer.get_image_filepath(img)
if self.options.tab_artwork_opacity != 1.0:
imgObj = Image.open(imgToDraw)
if imgObj.mode != "RGBA":
imgObj = imgObj.convert("RGBA")
alpha = imgObj.split()[3]
alpha = ImageEnhance.Brightness(alpha).enhance(
self.options.tab_artwork_opacity
)
imgObj.putalpha(alpha)
imageBytes = BytesIO()
imgObj.save(imageBytes, "PNG")
imageBytes.seek(0)
imgToDraw = ImageReader(imageBytes)
self.canvas.drawImage(
DividerDrawer.get_image_filepath(img),
imgToDraw,
1,
0,
item.tabWidth - 2,

View File

@ -316,6 +316,14 @@ def parse_opts(cmdline_args=None):
dest="no_tab_artwork",
help="Don't show background artwork on tabs.",
)
group_tab.add_argument(
"--tab-artwork-opacity",
type=float,
default=1.0,
help="Multiply opacity of tab background art by this value; "
"can be used to make text show up clearer on dark backrounds, "
"particularly on printers that output darker than average",
)
group_tab.add_argument(
"--use-text-set-icon",
action="store_true",