ClojureでJDeliを実行する
以下のチュートリアルでは、ClojureでJDeliを使用する方法を説明します。
このコードスニペットは、例としてJPGからPNGへの変換を使用しています。この例では、ビルドツールとしてLeiningen を使用しています。
jdeli.jarを/libフォルダに配置してください。
project.clj
(defproject jdeli-clojure "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.11.1"]]
:jvm-opts ["-Djava.awt.headless=true" "-Xbootclasspath/a:lib/jdeli.jar"]
:main ^:skip-aot jdeli-clojure.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})
core.clj
(ns jdeli-clojure.core
(:import [com.idrsolutions.image JDeli]
[java.io File]
[java.awt.image BufferedImage])
(:gen-class))
(defn -main
"Convert JPG to PNG using JDeli"
[& args]
(let [input-file (File. "jpgFile.jpg")
output-file (File. "pngFile.png")
image (JDeli/read input-file)]
(JDeli/write image "png" output-file)))
