Skip to content
Snippets Groups Projects
Commit d29cfc32 authored by Mayr, Hannes's avatar Mayr, Hannes
Browse files

Custom position and size of qrcode for mpl engine.

parent 724814a6
Branches
Tags
6 merge requests!65Release v0.3.0,!64New year developments,!63Improve handling of long IDs,!62Export imported modules,!61Custom IDs,!60Enable customization of plotted IDs
......@@ -25,7 +25,13 @@ IMGS_AS_LIST = [IMG1, IMG2]
# Example for how to use tagplot with image files
FIGS_AND_IDS = tagplot(
IMGS_AS_LIST, "image", prefix=PROJECT_ID, id_method="time", location="west"
IMGS_AS_LIST,
"image",
prefix=PROJECT_ID,
id_method="time",
location="west",
qr_size=70,
qr_position=(0.5, 0.5),
)
# Required arguments: tagplot(images as list, desired plot engine)
......
......
......@@ -40,7 +40,14 @@ FIGS_AS_LIST = [FIG1, FIG2]
# Example for how to use tagplot with matplotlib figures
FIGS_AND_IDS = tagplot(
FIGS_AS_LIST, "matplotlib", location="west", id_method="random", prefix=PROJECT_ID
FIGS_AS_LIST,
"matplotlib",
location="west",
id_method="random",
prefix=PROJECT_ID,
qrcode=True,
# qr_position=(0.5, 0.5),
qr_size=50.5,
)
# Required arguments: tagplot(images as list, desired plot engine)
......
......
......@@ -41,6 +41,11 @@ class PlotOptions:
qrcode : bool, optional
Experimental support to encode the ID in a QR code on the exported plot.
Default: False.
qr_position : tuple, optional
Position of the bottom right corner of the QR Code on the plot in relative
(x, y) coordinates. Default: (1, 0).
qr_size: int or float, optional
Size of the QR code in arbitrary units. Default: 100.
id_on_plot: bool, optional
Print ID on the plot. Default: True.
"""
......@@ -54,6 +59,8 @@ class PlotOptions:
self.prefix = kwargs.get("prefix", "")
self.id_method = kwargs.get("id_method", "time")
self.qrcode = kwargs.get("qrcode", False)
self.qr_position = kwargs.get("qr_position", (1, 0))
self.qr_size = kwargs.get("qr_size", 100)
self.id_on_plot = kwargs.get("id_on_plot", True)
def __str__(self):
......
......
......@@ -51,6 +51,11 @@ def tagplot(figs, engine, **kwargs):
qrcode : bool, optional
Experimental support to encode the ID in a QR code on the exported plot.
Default: False.
qr_position : tuple, optional
Position of the bottom right corner of the QR Code on the plot in relative
(x, y) coordinates. Default: (1, 0).
qr_size: int or float, optional
Size of the QR code in arbitrary units. Default: 100.
id_on_plot: bool, optional
Print ID on the plot. Default: True.
......
......
......@@ -45,12 +45,12 @@ def tagplot_image(plotid_object):
fontsize = 12
font = ImageFont.load_default()
if plotid_object.font:
try:
# Absolute path to font file (.ttf or .otf) has to be given
font = ImageFont.truetype(plotid_object.font, fontsize)
except OSError:
warnings.warn("Font was not found.\nplotID continues with fallback font.")
# if plotid_object.font:
# try:
# # Absolute path to font file (.ttf or .otf) has to be given
# font = ImageFont.truetype(plotid_object.font, fontsize)
# except OSError:
# warnings.warn("Font was not found.\nplotID continues with fallback font.")
for i, img in enumerate(plotid_object.figs):
img_id = plotid_object.prefix + create_id(plotid_object.id_method)
......@@ -73,8 +73,18 @@ def tagplot_image(plotid_object):
if plotid_object.qrcode:
qrcode = create_qrcode(img_id)
qrcode.thumbnail((100, 100), Image.ANTIALIAS)
img.paste(qrcode, box=(img.width - 100, img.height - 100))
qrcode.thumbnail(
(plotid_object.qr_size, plotid_object.qr_size), Image.ANTIALIAS
)
img.paste(
qrcode,
box=(
img.width * plotid_object.position[0],
img.height * (1 - plotid_object.position[1])
# img.width * plotid_object.qr_position[0] - plotid_object.qr_size,
# img.height * (1 - plotid_object.qr_position[1]),
),
)
plotid_object.figs[i] = img
figs_and_ids = PlotIDTransfer(plotid_object.figs, plotid_object.figure_ids)
......
......
......@@ -63,8 +63,16 @@ def tagplot_matplotlib(plotid_object):
if plotid_object.qrcode:
qrcode = create_qrcode(fig_id)
qrcode.thumbnail((100, 100), Image.ANTIALIAS)
fig.figimage(qrcode, fig.bbox.xmax - 100, 0, cmap="bone")
qrcode.thumbnail(
(plotid_object.qr_size, plotid_object.qr_size), Image.ANTIALIAS
)
# fig.figimage(qrcode, fig.bbox.xmax - 100, 0, cmap="bone")
fig.figimage(
qrcode,
fig.bbox.xmax * plotid_object.qr_position[0] - plotid_object.qr_size,
fig.bbox.ymax * plotid_object.qr_position[1],
cmap="bone",
)
fig.tight_layout()
figs_and_ids = PlotIDTransfer(plotid_object.figs, plotid_object.figure_ids)
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment