Fork me on GitHub
#off-topic
<
2023-03-06
>
tengstrand14:03:07

Does anyone know of a library that can convert text into an image (e.g. png)? I have found code examples in Java, but it feels like there should be a Java library somewhere out there that I can use from Clojure.

thomas14:03:09

maybe shell out to imagemagick ?

tengstrand14:03:05

It looks like it can manipulate images. I want to create images from e.g. the output from different shell commands. And I want to include that into a tool, that I build in Clojure, so a Java or Clojure library would solve my problem. After a quick look at ImageMagic, it didn't seem to support that.

tengstrand14:03:08

I know how the output will look like, so converting text to an image is what I really need (as a library).

Daniel Gerson14:03:20

Would just be a case of saving the buffer I assume? cc @U050UBKAA

tengstrand14:03:08

This looks interesting! I think I will be able to use it. Thanks!

2
Rupert (All Street)14:03:58

You could generate an SVG which is a relatively straightforward XML format. You can then convert SVG to png/gif/jpeg etc. One approach is to create an SVG using an SVG editor like Inkscape. Then find/replace strings in the SVG XML using clojure.

Daniel Gerson14:03:12

I think Skia is better (given it's the rendering engine in Chrome) and is used for SVG renderings etc. You're just skipping the outsourcing step.

tengstrand14:03:36

Will look into that also. Thanks!

Daniel Gerson16:03:54

Yeah, if it works for your use case Clojure2D is probably better because you don't have to worry about shipping native binaries. Skia is a powerful alternative though.

lread16:03:31

I do a https://github.com/clj-commons/rewrite-clj/blob/d6d7885fc573dda35ddc06428ae2a9c199f00f50/script/doc_update_readme.clj#L133-L150 on some of the projects I work on with https://github.com/clj-commons/etaoin to generate https://github.com/clj-commons/rewrite-clj/tree/main#contributors for folks who contribute. Works well enough for my use case. Basically: -> hiccup->html/css->browser->screenshot. It's a bit heavy tho, ya? And can sometimes render very slightly differently with a new browser release.

orestis08:03:50

AWT has support for doing this without any external libraries. https://www.baeldung.com/java-add-text-to-image

👍 2
Danilo Oliveira20:03:18

My first Clojure macro. Now I have Erlang in Clojure lol

🙌 2
Danilo Oliveira20:03:35

This was just an exercise, I know there is the pulsar library. There is also Akka for the JVM, but sadly it was turned into a comercial product by Lightbend

Danilo Oliveira20:03:24

I wanted to manage impure stuff from Java libraries in a concurrently safe way and figured out Clojure agents are not ideal for that. Then I realized with some effort I can use Go blocks like actors

Danilo Oliveira20:03:42

That's why Lisps are better than other languages. If I want something baked into the language, first I write a very detailed email to Brian Goetz, then I pray he will read and be convinced

Danilo Oliveira20:03:04

Then I wait 15 years for the JEP to be accepted. in Clojure I just have to write macros lol

Daniel Craig20:03:57

Clojure has agents which are like actors right?

Danilo Oliveira20:03:36

Agents are similar, but they expose the state to anyone be able to deref @

Daniel Craig20:03:01

shows what I know 😆

Danilo Oliveira20:03:09

An actor state is completely protected from external access, you have to send a message and ask the actor

❤️ 2
Danilo Oliveira20:03:21

In Akka you can keep the actor state mutable and dirty, as long the messages are immutable. Clojure agents only accept immutable values as state