Running JDeli in Clojure
Table of contents
Introduction
The following tutorial shows you how to use JDeli in Clojure.
Prerequisites
Code Example
This code snippet uses JPG to PNG conversion as an example. This example uses Leiningen as the build tool.
Put jdeli.jar in the /lib folder.
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)))