add --tab-artwork-opacity flag (#259)
turn down background opacity to help text show up better against dark backgrounds
This commit is contained in:
parent
43d1e5eae0
commit
3f571cb2af
@ -6,11 +6,14 @@ import sys
|
|||||||
|
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
|
||||||
|
from PIL import Image, ImageEnhance
|
||||||
|
|
||||||
from reportlab.lib.units import cm
|
from reportlab.lib.units import cm
|
||||||
from reportlab.pdfbase import pdfmetrics
|
from reportlab.pdfbase import pdfmetrics
|
||||||
from reportlab.lib.styles import getSampleStyleSheet
|
from reportlab.lib.styles import getSampleStyleSheet
|
||||||
from reportlab.platypus import Paragraph, XPreformatted
|
from reportlab.platypus import Paragraph, XPreformatted
|
||||||
from reportlab.lib.enums import TA_JUSTIFY, TA_CENTER, TA_LEFT
|
from reportlab.lib.enums import TA_JUSTIFY, TA_CENTER, TA_LEFT
|
||||||
|
from reportlab.lib.utils import ImageReader
|
||||||
from reportlab.pdfgen import canvas
|
from reportlab.pdfgen import canvas
|
||||||
from reportlab.pdfbase.ttfonts import TTFont
|
from reportlab.pdfbase.ttfonts import TTFont
|
||||||
from reportlab.pdfbase.pdfmetrics import stringWidth
|
from reportlab.pdfbase.pdfmetrics import stringWidth
|
||||||
@ -1141,6 +1144,8 @@ class DividerDrawer(object):
|
|||||||
return w
|
return w
|
||||||
|
|
||||||
def drawTab(self, item, wrapper="no", backside=False):
|
def drawTab(self, item, wrapper="no", backside=False):
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
card = item.card
|
card = item.card
|
||||||
# Skip blank cards
|
# Skip blank cards
|
||||||
if card.isBlank():
|
if card.isBlank():
|
||||||
@ -1190,8 +1195,22 @@ class DividerDrawer(object):
|
|||||||
# draw banner
|
# draw banner
|
||||||
img = card.getType().getTabImageFile()
|
img = card.getType().getTabImageFile()
|
||||||
if not self.options.no_tab_artwork and img:
|
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(
|
self.canvas.drawImage(
|
||||||
DividerDrawer.get_image_filepath(img),
|
imgToDraw,
|
||||||
1,
|
1,
|
||||||
0,
|
0,
|
||||||
item.tabWidth - 2,
|
item.tabWidth - 2,
|
||||||
|
|||||||
@ -316,6 +316,14 @@ def parse_opts(cmdline_args=None):
|
|||||||
dest="no_tab_artwork",
|
dest="no_tab_artwork",
|
||||||
help="Don't show background artwork on tabs.",
|
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(
|
group_tab.add_argument(
|
||||||
"--use-text-set-icon",
|
"--use-text-set-icon",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user