This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-13
Channels
- # announcements (2)
- # beginners (15)
- # calva (6)
- # cider (3)
- # cljsrn (1)
- # clojure (33)
- # clojure-hk (4)
- # clojure-uk (9)
- # clojurescript (13)
- # cursive (5)
- # datomic (6)
- # figwheel-main (1)
- # fulcro (5)
- # graalvm (12)
- # instaparse (1)
- # kaocha (1)
- # nrepl (6)
- # off-topic (5)
- # pedestal (10)
- # quil (8)
- # reitit (2)
- # ring (5)
- # shadow-cljs (10)
- # sql (1)
- # vim (13)
And (def myfn (partial foo "bar"))
is copying a pointer/reference to the value of foo
, not all of the code of foo
.
I'm trying to rotate an image with a transparent background an arbitrary amount of degrees (e.g. 261), and I don't care if I lose the corners of the image (they're empty anyways). I've found collage
, ez-image
and imgsclr
but all seem to only support rotating in multiples of 90. Rotating and saving the image to disk are the only things I need. Any ideas?
because rotating fixed pixels 261 degrees is a bit harder 🙂
if i'd have to do it i'd probably implement it myself... just for the educational ride 🙂
@slack.jcpsantiago I believe clojure2d has a way to do that using the underlying Java Graphics2D library, however the API is not so friendly for doing pure image transformations
yep. should be possible just to tell graphics2d to draw a rotated image on an offscreen image buffer and capture the result from there
doesn't really look that hard
not sure about the outcome quality though, should probably check it out before you invest much time on it 🙂
Now I want to implement that, just for fun
It's really fun to work with linear algebra, which I assume would do the trick
(ns scratch
(:require
[clojure2d.core :as c2d]
[ :as io])
(:import [java.awt Graphics2D]
[java.awt.image BufferedImage]
[javax.imageio ImageIO]))
(defn rotate-around-center
[img degrees]
(let [w (.getWidth img)
h (.getHeight img)]
(c2d/with-canvas-> (c2d/canvas w h)
(c2d/translate (/ w 2) (/ h 2))
(c2d/rotate (* degrees (/ Math/PI 180)))
(c2d/translate (- (/ w 2)) (- (/ h 2)))
(c2d/image img)
(c2d/get-image))))
(-> ""
(io/as-url)
(ImageIO/read)
(rotate-around-center 261)
(ImageIO/write "png" (io/as-file "out.png")))
@qythium that seems to the trick for me, but clojure2d
seems to be discarding background transparency? source code says "Canvas is transparent by default." hum trying to figure that out, then need to figure out how to pay you a beer 😄
Oh, I'm on version 1.2.0-SNAPSHOT of clojure2d, looks like they made a breaking change to the default canvas transparency
look how much simpler it is in Python though:
from PIL import Image
Image.open("airplane_small.png").rotate(261).save("out.png")
It almost must exist in some Java library somewhere, but I don't have enough knowledge of existing libraries to suggest one.
https://github.com/cnuernber/libpython-clj and do it in clojure-python to your hearts content 🙂.
btw here's where all the code went into https://github.com/jcpsantiago/controltower Thanks again @qythium app makes sense now haha