Link
Skip to main content

Running JDeli in Clojure

Table of contents

  1. Introduction
  2. Prerequisites
  3. Code Example

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)))

Why JDeli?

  • Support image formats such as AVIF, HEIC and JPEG XL (AVIF soon) that are not supported in Java.
  • Process images up to 3x faster than ImageIO and alternative Java image libraries.
  • Prevent JVM crashes caused by native code in other image libraries such as ImageIO.
  • Handle JPEG, PNG, TIFF image file formats fully in Java.
  • Keep your Image files secure as JDeli makes no calls to any external system or third party library.

Learn more about JDeli

Start Your Free Trial