Created
May 8, 2013 16:26
-
-
Save bbirec/5541650 to your computer and use it in GitHub Desktop.
scale and draw watermark on the image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns oneroom.image | |
(:import javax.imageio.ImageIO | |
java.awt.image.BufferedImageOp | |
java.awt.geom.AffineTransform | |
java.awt.Image | |
java.io.File | |
org.imgscalr.Scalr) | |
(:refer-clojure :exclude [load])) | |
(defn load [f] | |
(ImageIO/read (if (string? f) | |
(File. f) | |
f))) | |
(defn save [img f] | |
(ImageIO/write img "png" (if (string? f) (File. f) f))) | |
(defn scale [img width height] | |
(Scalr/resize img | |
(int width) | |
(int height) | |
(into-array BufferedImageOp []))) | |
(defn draw-watermark [target-img wm-img x y] | |
(let [g (.createGraphics target-img) | |
transform (AffineTransform. 1.0 0.0 0.0 1.0 | |
(double x) | |
(double y))] | |
(.drawImage g wm-img transform nil) | |
target-img)) | |
;; | |
(defn -test [& [target mark out]] | |
(let [a (load (or target "/Users/bbirec/Desktop/plus.png")) | |
b (load (or mark "/Users/bbirec/Desktop/trash.png"))] | |
(-> a | |
(scale 500 500) | |
(draw-watermark b 0 0) | |
(save (or out "/Users/bbirec/Desktop/out.png"))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment