add clojure functions to get ImageInputStreams by url/file
This commit is contained in:
parent
16ab2acd6d
commit
f813021fa8
|
@ -1,10 +1,11 @@
|
||||||
(ns clj-image2ascii.core
|
(ns clj-image2ascii.core
|
||||||
(:import (javax.imageio ImageIO)
|
(:import (javax.imageio ImageIO)
|
||||||
|
(javax.imageio.stream ImageInputStream)
|
||||||
|
(java.awt RenderingHints Graphics2D)
|
||||||
(java.awt.image BufferedImage)
|
(java.awt.image BufferedImage)
|
||||||
(java.net URL)
|
(java.net URL)
|
||||||
(java.io File)
|
(java.io File InputStream)
|
||||||
(java.awt RenderingHints Graphics2D)
|
(clj_image2ascii.java ImageToAscii AnimatedGif ImageFrame)))
|
||||||
(clj_image2ascii.java ImageToAscii)))
|
|
||||||
|
|
||||||
(defn get-image-by-url
|
(defn get-image-by-url
|
||||||
"returns a BufferedImage loaded from the URL specified, or null if an error occurs"
|
"returns a BufferedImage loaded from the URL specified, or null if an error occurs"
|
||||||
|
@ -20,6 +21,19 @@
|
||||||
(ImageIO/read file)
|
(ImageIO/read file)
|
||||||
(catch Exception ex))))
|
(catch Exception ex))))
|
||||||
|
|
||||||
|
(defn get-image-stream-by-url
|
||||||
|
(^ImageInputStream [^URL url]
|
||||||
|
(try
|
||||||
|
(let [^InputStream stream (.openStream url)]
|
||||||
|
(ImageIO/createImageInputStream stream))
|
||||||
|
(catch Exception ex))))
|
||||||
|
|
||||||
|
(defn get-image-stream-by-file
|
||||||
|
(^ImageInputStream [^File file]
|
||||||
|
(try
|
||||||
|
(ImageIO/createImageInputStream file)
|
||||||
|
(catch Exception ex))))
|
||||||
|
|
||||||
(defn scale-image
|
(defn scale-image
|
||||||
"takes a source BufferedImage and scales it proportionally using the new width,
|
"takes a source BufferedImage and scales it proportionally using the new width,
|
||||||
returning the scaled image as a new BufferedImage"
|
returning the scaled image as a new BufferedImage"
|
||||||
|
|
Loading…
Reference in a new issue