BigJk / snd

Sales & Dungeons — Thermal Printer as D&D / TTRPG Utility
https://sales-and-dungeons.app/
MIT License
474 stars 17 forks source link

Trouble printing images loaded from URL #43

Closed MrG4dget closed 1 year ago

MrG4dget commented 1 year ago

Hi guys!

Not sure if anyone can reproduce this, but somehow I'm running into trouble when adding images from a URL to the Print skeleton. I use a global config (Checkbox) no show/hide the image. In the preview the image is shown just fine. However the print itself shows no image. Other image elements (Icons and frame) are printing fine. Also using the "Save Image" button does not show the added image.

Expected Output

Output I got:

But when I edit the Template and load the data Skeleton of the same item, it prints fine as long as I load the data skeleton of the same item. If I use the default (last used entry) in the edit mode, it gives me the error:

Error: html to image rendering failed: png: invalid format: invalid image size: 0x0

Re-loading the item in the "Data Skeleton" page solves that problem and it prints the image just fine.

I added some image filtering options so that the output is kind of usable (values can be changed via global config). Maybe someone else needs this, so I'm posting my print template here.

Print Template

Print Template ```html {% set color = "black" %}
{{ it.name }}
{{ it.dndbeyond.type+" - " if it.dndbeyond.type}} {{ it.Item.system.rarity | capitalize }} {{ "("+it.requires_attunement+")" if it.requires_attunement }}
{{ it.desc | replace(r/\*\*([^\*]*)\*\*/g, '$1') | replace(r/_([^_]*)_/g, '$1') | replace(r/\n[\*-] /g, '\n• ') | replace("@Compendium[dnd5e.rules.w7eitkpD7QQTB6j0]","") | safe }} {% if config.showImage %} {% endif %}
{{ it.type }}
{% if it.weight %} {{ (" "+it.weight+"lbs" if it.weight)+(" " if it.price)}} {% endif %} {% if config.value_overwrite > 0 %} {{ "Value: "+config.value_overwrite+"Gp" if config.value_overwrite}} {% else %} {{ "Value: "+it.price+"Gp" if it.price}} {% endif %}
```
MrG4dget commented 1 year ago

I'm suspecting that there might be an issue with my use of global configs. it looks as if changing them, does not lead to the values being applied correctly.

BigJk commented 1 year ago

Found the issue. The global config wasn't properly applied when the final printing happened. A new version with the fix will be available in a few minutes. It would be great if you could verify that it works so I can close the issue and thanks a lot for bringing this up. Feel free to open more issues if you find any other bugs! 😄

MrG4dget commented 1 year ago

That seems to solve the issue! Awesome work!