Html
In Diffusion Studio, HTML elements are treated as images. Currently, loading HTML with dynamic content is not supported, as HTML is rendered as an SVG inside a <foreignObject>. However, HTML is very useful for rendering responsive layouts and utilizing CSS features.
Layout
Your HTML must follow a strict layout. Ensure that your entire markup is wrapped by a <body>
tag and all your styles are inside a <style>
tag. I can recommended using this template.
Note: The div encapsulating the span is optional, also the style tag must not be wrapped by a head tag.
Manipulating the HTML
To load the HtmlSource
, use the following code:
Diffusion Studio will interpret the contents by opening the HTML inside an IFrame, allowing you to manipulate the DOM of the source:
Rendering HTML to Canvas
Construct a HtmlClip
from your source with the following code:
By default, the height and width of the clip are defined by your CSS. You can change the dimensions of the clip, but this will only scale your "HTML Image" and will not change the DOM.
Note: If you change the DOM via
source.document
after the clip has been added to the composition, you need to trigger an update of the clip by runninghtml.set()
.
Note: External images and fonts cannot be loaded inside a foreign object. Replace them with base64 encoded strings. For reference, see the Reddit Stories example.