nextjournal

Carlo 2022-01-25T10:25:09.010700Z

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?

mkvlr 2022-01-25T11:34:04.012600Z

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.

Carlo 2022-01-25T11:35:40.013100Z

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

Carlo 2022-01-25T11:39:36.013300Z

@mkvlr

mkvlr 2022-01-25T11:44:27.013500Z

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

mkvlr 2022-01-25T11:44:53.013700Z

or InputStream

Carlo 2022-01-25T11:45:12.013900Z

amazing! I'll try that right now 🙏

mkvlr 2022-01-25T11:34:16.013Z

I also plan to cut a release later today

1
🙂 1