Embed pictures with pict?
I have seen that it is possible in Scribble to embed pictures generated with
pict just by writing code like this in a document:
(require pict) @(colorize (filled-ellipse 40 40) "beige").
I tried to do the same in a pollen page as follows:
◊(colorize (filled-ellipse 40 40) "beige").
But I received a contract violation:
decode-elements: contract violation expected: txexpr-elements? ...
Is there a proper way to do what I wanted?
Scribble is converting the
pict object to a
png, saving it, and generating a link to the new file. So you could make a macro that does the same housekeeping. (Edit: I take it back, you can do it with a function not a macro):
#lang pollen ◊(require pict) ◊(pict-as-png (colorize (filled-ellipse 40 40) "red"))
#lang racket/base (require racket/class pict) (provide pict-as-png) (define (pict-as-png pict) (let ([png-name (format "~a.png" (gensym))]) (send (pict->bitmap pict) save-file png-name 'png) `(img ((src ,png-name)))))
@mbutterick Thank you very much for the help! Another thing I have tried out (which worked) is encoding the image as base-64 and inlining it into the html. Your solution is probably better for caching purposes.
Sure. The main idea is that whatever comes back from your Pollen function has to be something that counts as a
Though it seems to be immovable folk wisdom at this point, I would not necessarily assume that the base64 approach is slower.
Deleting a branch is permanent. It CANNOT be undone. Continue?