1

I am writing an image-upload system using Clojure. I use a Java library javadoc to make a thumbnail image.

(defn upload-file [file]
  (let [file-name (file :filename)
        actual-file (file :tempfile)
        image (Thumbnails/fromFiles (java.util.ArrayList. [actual-file]))
        image-jpg (.outputFormat image "jpg")
        thumb (.forceSize image-jpg 250 150)]
        ...

My code changes both thumb var and image-jpg var, but I want to have two separate images (one with normal size and thumb). How do I make a copy of image-jpg to change its size?

Taylor Wood
  • 15,886
  • 1
  • 20
  • 37

1 Answers1

0

You could just try doing the same operation again on the same actual-file. And create a function that you call twice:

(defn make-thumb [width height file]
  (let [image (Thumbnails/fromFiles (java.util.ArrayList. [file]))
        image-jpg (.outputFormat image "jpg")]
    (.forceSize image-jpg width height)))

Another way would be to deep copy image. See How do you make a deep copy of an object in Java? and do the same thing in Clojure.

Community
  • 1
  • 1
Chris Murphy
  • 6,411
  • 1
  • 24
  • 42