berteh / ScribusGenerator

Create beautiful documents with data. Open source pdf (and Scribus) template and mail-merge alternative.
http://berteh.github.io/ScribusGenerator/
MIT License
247 stars 37 forks source link

add support for inline images - add images dynamicaly into a text frame #213

Open flagadur opened 1 year ago

flagadur commented 1 year ago

It would be super awesome to insert images into text frame dynamically. I don't think it's possible yet, is it? Thanks ;)

Example : My Text_Frame : "%VAR_my_text% my_text : "Inflict 3 %VAR_image_for_damage% to the target %VAR_image_for_creature%

berteh commented 1 year ago

It is perfectly feasible... and was actually one of my reasons to develop the tool, just not in a single dynamic text but between multiple dynamic texts (that can all be inserted in a single text frame, in sequence).

Since variables (text or images) that would be empty after the substitution are removed by ScribusGenerator you should be able to get the expected result.

To take your example I'd cut the data somewhere along the table below, and design the Scribus template accordingly while playing with the anchor of the image frames so that it keeps aligned with the preceding character. Empty texts and images placeholders will be remove when empty, no worry there.

text1 img12 text2 img23 text3 img34 text4
Inflict 3 ./pic/dmg-inline.png to the target ./pic/creature/basilik-inline.png
Inflict 1 ./pic/dmg-inline.png to every ./pic/creature/blue.png creature in the oponent field.
Recover 3 ./pic/health-inline.png and add 2 ./pic/defence-inline.png tokens to all your ./pic/creature/purple.png creatures
flagadur commented 1 year ago

Yayyy ! Thanks for the tips!

I don't know how to "play with anchors" though... I tried inline objectifs but it doesn't seem to work with Scribus Generator substitution : https://www.youtube.com/watch?v=8bdQNEVEtDo&ab_channel=GraphicdesignforFree

berteh commented 1 year ago

you're right. the "inline" object didn't exist yet so I played with absolute positionning and text alignement (right align for text left of the image, for instance) to mimic some inline.

It should be possible to adapt the SG code to handle inline objects without too much work, will have a look but I don't exactly know when... if you wanna give it a shot feel free to hack the code and submit a pull request.

flagadur commented 1 year ago

So this way you can only add one image into a text but it's a start! I'm afraid I'm not skilled enough to improve your code... I would love to though. If you had some time for it, it would be awesome, but if not no worries, your project is fabulous. It's my day to day tool for work ;) If you need some sample projects to share new people with, don't hesitate to ask!