Search code examples
clojureprocessingquil

How to find the width and height of an image with quil in clojure


I am trying to find the width of a loaded image in clojure. In processing I would do this,

    PImage img=loadImage("image.jpg");
    int x=img.width;
    int y=img.height;

I tried to do this same in clojure but it won't work

   (defn loadwebimg []
     (let [filelst (map (fn [f] (.getName f)) (.listFiles (File. (str datadir))))
           imgf (first (shuffle filelst))
           webimg (load-image (str datadir imgf))
           ]
      (image webimg 0 0) 
      (println webimg.height))

Solution

  • If webimg is an object when you would use the . special form to read its fields like you do for the file objects you use above it.

    as user100464 points out:

    (println webimg.height)
    

    would become

    (println (. webimg height)
    

    or

    (println (.height webimg))