Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can also do this with node

    npm install nbb canvas
create a draw.cljs file with the code below

    (ns draw.core
      (:require
       ["fs" :as fs]
       ["canvas" :refer (createCanvas)]))

    (def width 400)
    (def height 400)
    (def canvas (createCanvas width height))
    (def ctx (.getContext canvas "2d"))

    (set! (.-fillStyle ctx) "#764abc")
    (.fillRect ctx 0 0 width height)

    (set! (.-fillStyle ctx) "#fff")
    (set! (.-textAlign ctx) "center")
    (set! (.-font ctx) "bold 50pt 'PT Sans'")
    (.fillText ctx "Hello World" (/ width 2) (/ height 2))

    (set! (.-strokeStyle ctx) "#fff")
    (.beginPath ctx)
    (.arc ctx 75 75 50 0 (* 2 js/Math.PI) true)
    (.moveTo ctx 110, 75)
    (.arc ctx 75 75 35 0 js/Math.PI false)
    (.moveTo ctx 65 65)
    (.arc ctx 60 65 5 0 (* 2 js/Math.PI) true)
    (.moveTo ctx 95 65)
    (.arc ctx 90 65 5 0 (* 2 js/Math.PI) true)
    (.closePath ctx)
    (.stroke ctx)

    (.writeFileSync fs "./hello.png" (.toBuffer canvas "image/png"))
and run to make a PNG

    npx nbb draw.cljs
as a bonus you can start nREPL and connect your editor to it for interactive development

    nbb nrepl-server :port 1337


Um.

You can, but I'm not sure why you would, or how it's relevant?

sips is installed by default, that's the only reason you'd use it over any number of other drawing tools.

Using node and clojure seems like it's more effort, more obscure and less functionality than any number of other things. If you're going to install something, install imagemagick.

If you're looking for something else kind of like sips, try hand coding an svg like:

    <svg xmlns="http://www.w3.org/2000/svg" width="500" height="500" viewBox="0 0 500 500">
    <rect x="3" y="3" width="200" height="200"></rect>
    </svg>
Then run the thumbnail generator on it:

    qlmanage -t -s 500 -o . junk.svg
Using clojure (nbb) for this seems... like a solution looking for a problem to solve.


Um.

This would not seem to be relevant only if you didn't bother reading the article in the submission. Once you do, you'll notice the following example there:

After some searching I found manicmaniac/sips-js-api which is the only place online I could see that documented how to use the sips --js option. Here's their example - save this in smile.js:

    const canvas = new Canvas(150, 150)
    canvas.beginPath()
    canvas.arc(75, 75, 50, 0, Math.PI * 2, true)
    canvas.moveTo(110, 75)
    canvas.arc(75, 75, 35, 0, Math.PI, false)
    canvas.moveTo(65, 65)
    canvas.arc(60, 65, 5, 0, Math.PI * 2, true)
    canvas.moveTo(95, 65)
    canvas.arc(90, 65, 5, 0, Math.PI * 2, true)
    canvas.stroke()
    const output = new Output(canvas, sips.outputPath)
    output.addToQueue()
Then run:

    sips -j smile.js -o smile.png
This produces an alpha-transparent PNG of a smiling face.

The obvious advantage of using node over sips is that it works on every platform. You'll also have to elaborate on what this additional effort you speak of is. If you have node installed, as practically everyone does nowadays, then the presumed effort is in having to run npm install?

Also, you obviously don't have to use Clojure, I chose it because that's the language I already use and like. You could just make a regular Js file as well.

Hope that helped clarify things for you.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: