Skip to content

Commit

Permalink
Support PNGs and JPGs in reportlets.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Aug 16, 2024
1 parent 12ed4b7 commit 04ad3b6
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion nireports/assembler/reportlet.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat
"name",
"_".join("%s-%s" % i for i in sorted(bidsquery.items())),
)

# Query the BIDS layout of reportlets
files = layout.get(**bidsquery)

Expand Down Expand Up @@ -269,6 +268,26 @@ def __init__(self, layout, config=None, out_dir=None, bids_filters=None, metadat
name=html_anchor,
style="; ".join(f"{k}: {v}" for k, v in style.items()),
)
elif ext in (".png", ".jpg", ".jpeg"):
entities = dict(bidsfile.entities)
if desc_text:
desc_text = desc_text.format(**entities)

try:
html_anchor = src.relative_to(out_dir)
except ValueError:
html_anchor = src.relative_to(Path(layout.root))
dst = out_dir / html_anchor
dst.parent.mkdir(parents=True, exist_ok=True)
copyfile(src, dst, copy=True, use_hardlink=True)

style = {"width": "100%"} if is_static else {}
style.update(config.get("style", {}))

stylestr = "; ".join(f"{k}: {v}" for k, v in style.items())
contents = f'<img src="{html_anchor}" style="{stylestr}"/>'
else:
raise RuntimeError(f"Unsupported file extension: {ext}")

if contents:
self.components.append((contents, desc_text))
Expand Down

0 comments on commit 04ad3b6

Please sign in to comment.