Skip to main content
Interwork Corporation
IDR Solutions Product Support Portal
モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動 モードの切替 ダーク/ライト/自動

ClojureでJDeliを実行する

目次

  1. はじめに
  2. 前提条件
  3. コード例

はじめに

以下のチュートリアルでは、ClojureでJDeliを使用する方法を説明します。

前提条件

  • マシンにClojure がインストールされていること
  • プロジェクトライブラリにJDeli jar が追加されていること

コード例

このコードスニペットは、例として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)))