Fork me on GitHub
#nextjournal
<
2022-01-25
>
Carlo10:01:09

Good morning! I have a question on clerk's viewers. I added:

(clerk/set-viewers! [{:pred #(instance? Path %)
                       :fetch-fn (fn [_ path] {:nextjournal/content-type "image/jpg"
                                               :nextjournal/value (Files/readAllBytes path)})
                       :render-fn (fn [blob] (v/html [:img {:src (v/url-for blob)}]))}])
so that I can use:
(fs/path "./art/sketch-01-001-0001-0558.jpg")
to display an image. But I wonder, why can't I do something like
(clerk/table
 `[[1 2] [3 ~(fs/path "./art/sketch-01-001-0001-0558.jpg")]])
to have an image in one of the cells of the table?

mkvlr11:01:04

hey @meditans, if you can use the git dep of Clerk this now comes with support for images, see https://github.com/nextjournal/clerk/blob/4862243b1d725a09c98ac08a7046a315e4b4c63e/notebooks/viewers/image.clj. There’s also some breaking changes of the viewer api, the render-fn now needs to be quoted to make it more explicit that it doens’t run on the JVM, see https://github.com/nextjournal/clerk/commit/e4acb372d33e0e66f38cafc140226ca89591114e. As to putting an image inside a table this is something I also want. I’ll try it later, it might require some small tweaks to support this.

Carlo11:01:40

thanks! Those examples focus on images from the internet; do I still need something more for local images?

mkvlr11:01:27

no, ImageIO/read takes all kinds of things, also java.io.Files

mkvlr11:01:53

or InputStream

Carlo11:01:12

amazing! I'll try that right now 🙏

mkvlr11:01:16

I also plan to cut a release later today

🙂 1
metal 1