Is there a way to write dynamic text to image?
If so, can someone provide some hint on how to do that?
Hello, the best way to do this is probably to pass an SVG containing the text as the overlay image passed to the overlayWith operation.
Good idea, thank you.
The image into which the text SVG is overlayed is resized (and cloned) multiple times -
the sharp SVG instance has to be resized then to achieve the same relative size.
However, resizing using the resize(...) sharp API method will
degrade the quality (apparently the SVG is rasterized when being loaded by sharp).
How can I achieve the same relative text/font/dimensions of a SVG
overlayed into a sharp image of varying dimensions?
svg is a text, so may be create each svg on the fly?
text-to-svg and vectorize-text both accept the font-size in pt.
Also there is kerning and other irregularities;
so in the end a reliable method for calculating the right font-size
for a specific width of resulting SVG text is needed.
"apparently the SVG is rasterized"
If you've not seen it, the density option of sharp's constructor can be used to alter the resolution at which vector inputs are converted to a bitmap.
Most helpful comment
Hello, the best way to do this is probably to pass an SVG containing the text as the overlay image passed to the overlayWith operation.