• Stars
    star
    135
  • Rank 269,297 (Top 6 %)
  • Language
    Clojure
  • Created over 11 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Resize/Crop/Rotate/Pad images in Clojure without any native install. Oh and do it Fast.

Clojure Image Resizer

Build Status

Clojars Project

(Drink to make small)

Make smaller Drink to make small

Why?

  • Very fast (supports hardware accelerated operations on most platforms)
  • No native libraries to install (I'm looking at you imagemagick)

Image Resizer under the hood wraps imgscalr.

Installation

Add the following dependency to your project.clj file:

Clojars Project

Usage

Pipelining Transforms

Image resizer creates tranforms which return fns that apply that transform to an image.

A number of transforms are supported:

  • resize
  • crop
  • pad
  • rotate

If you want to perform a number of operations across an image (such as resize, crop, flip & pad):

(require [image-resizer.crop :refer :all])
(require [image-resizer.resize :refer :all])
(require [image-resizer.pad :refer :all])
(require [image-resizer.rotate :refer :all])

(-> image
    ((resize-fn 100 100))
    ((crop-fn 100 100))
    ((rotate-vertically-fn))
    ((pad-fn 10)))


;Or if you want to apply a transform to a batch of images in parallel:

(doall (clojure.core/pmap (resize-fn 100 100) [image1 image2 image3 image4]))

Tweaking quality/speed ratio

You can tweak your preferences for a resize transform. Favouring speed or quality:

(require [image-resizer.resize :refer :all])
(require [image-resizer.scale-methods :refer :all])

(resize-fn 100 100 ultra-quality) ;best quality
(resize-fn 100 100 speed)         ;fast as possible resize

Lazy helpers around transforms

If creating your own pipelines seems a bit funky, you can use some nice helpers for commmon operations:

(require [image-resizer.core :refer :all])

;Resize an image while respecting original ratio
;Notice how the height is not 10 to respect the ratio of the image
(resize (file "white-rabbit.jpg") 10 10)          ; => #<BufferedImage width=10 height=4>

;Resize an image to a width
(resize-to-width (file "queen-of-hearts.jpg") 10) ; => #<BufferedImage width=10 height=4>

;Resize an image to a height
(resize-to-height (file "cheshire-cat.jpg") 10)   ; => #<BufferedImage width=5 height=10>

;Force width and a height resize (ignoring ratios)
(force-resize (file "cheshire-cat.jpg") 10 1000)   ; => #<BufferedImage width=10 height=1000>

;Crop the image width
(crop-to-width (file "tea-party/mad-hatter.jpg") 10) ; => #<BufferedImage width=10 height=1000>

;Crop the image height
(crop-to-height (file "tea-party/mad-hatter.jpg") 10) ; => #<BufferedImage width=1000 height=10>

;Crop the image width and height
(crop (file "tea-party/mad-hatter.jpg") 10 20) ; => #<BufferedImage width=10 height=20>

;Crop the image width and height from a coord
(crop-from (file "tea-party/mad-hatter.jpg") 6 7 10 20) ; => #<BufferedImage width=10 height=20>

;Resize the image maintaining proportions and then crop it to the specified width and height
(resize-and-crop (file "tea-party/mad-hatter.jpg") 10 10) ; => #<BufferedImage width=10 height=10>

Turning BufferedImage into something useful

(require [image-resizer.format :as format])

;Saving as an auto-named file
(format/as-file
  (resize (file "tea-party/mad-hatter.jpg") 10 10)
  "/tmp/tea-party/mad-hatter.jpg") ; => "/tmp/tea-party/mad-hatter_10x5.jpg"

;Saving under a specific name
(format/as-file
  (resize (file "tea-party/mad-hatter.jpg") 10 10)
  "/tmp/tea-party/tiny-hatter.jpg"
  :verbatim) ; => "/tmp/tea-party/tiny-hatter.jpg"

;To a stream (Useful for s3)
(format/as-stream (resize (file "tea-party/mad-hatter.jpg") 10 10) "jpg") ; => #<ByteArrayInputStream>

Contributors

License

(The MIT License)

Copyright (c) 2013-present Joseph Wilk

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

amrita

A polite, well mannered and thoroughly upstanding testing framework for Elixir
Elixir
199
star
2

semanticpy

A collection of semantic functions for python - including Latent Semantic Analysis(LSA)
Python
159
star
3

rsemantic

A document vector search with flexible matrix transforms. Currently supports Latent semantic analysis and Term frequency - inverse document frequency
Ruby
146
star
4

musical-creativity

Models of Musical Creativity (in Clojure)
Clojure
131
star
5

circuit-breaker

Circuit breaker for Clojure
Clojure
129
star
6

tlearn-rb

Recurrent Neural Network library for Ruby
C
96
star
7

pairwise

Ruby based tool for selecting a smaller number of test input combinations (using pairwise generation) rather than exhaustively testing all possible permutations.
Ruby
84
star
8

shaderview

Light show for live coding
GLSL
75
star
9

strangeloop2014

Come with us now on a journey ♪
Clojure
64
star
10

mud

MUD is a layer over Overtone to make live composition more powerful and immediate.
Clojure
60
star
11

hystrix-event-stream-clj

Easy way to output a Hystrix event stream in Clojure.
Clojure
55
star
12

functions-as-patterns

Exploring patterns as a means of understanding and documenting functions.
Clojure
46
star
13

japanese-mosaic-logic-puzzle

Problem for Programming challenge October
Ruby
42
star
14

rspec-rr

Helping Rspec and Rspec-rails play nicely with RR the test double framework
Ruby
27
star
15

stereotype

A fixture library for setting up test data in Clojure
Clojure
26
star
16

pronounce

Find how to pronounce words by breaking them up into their phones.
Ruby
24
star
17

overtone.device.launchpad

Using Launchpad with Overtone and Clojure
Clojure
23
star
18

overtone.orchestra

Orchestra for Overtone
Clojure
21
star
19

overtone.synths

A collection of synths
Clojure
17
star
20

closure-bricks.el

What would scheme bricks look like in emacs...
Emacs Lisp
13
star
21

cucumber_cocktails

A collection of my Cucumber utils
Ruby
10
star
22

finger-smudge

Music for Machines. Exploring the smudges of fingerprinting digital music.
Clojure
10
star
23

iwfms

A Intelligent Workflow Management System using Prolog and PHP that uses artificial intelligence planning methodologies and Event Calculus workflow specifications.
PHP
9
star
24

shader-pi

Interactive Shaders for SonicPi
Ruby
8
star
25

ofxEmacsEditor

Emacs editor for openframeworks
C++
8
star
26

overtone.device.push

Using Ableton push with Overtone and Clojure
8
star
27

creative-machine

Experiments in creative AI
Ruby
8
star
28

synthatron

Generator of synths for use with Supercollider. Evolving synths for evil or good.
Clojure
7
star
29

midje-junit-formatter

Junit Formatter for Midje
Clojure
6
star
30

irobat

The Iphone and Cucumber sitting in a tree K-I-S-S-I-N-G. EXPERIMENTAL!
Ruby
6
star
31

qscintilla

QScintilla version (2.9/2.10) that introduces transparent background but not text.
C++
6
star
32

rr-tmbundle

RR (Double Ruby) test double framework - TextMate bundle
5
star
33

nicos-ip

Corrupted Sonic Pi. Highly dangerous. May infect thought.
Ruby
4
star
34

presentations

Joseph Wilk's Presentations
4
star
35

the-nature-of-sound

♫ Clojure library for exploring the nature of sounds. May contain large traces of C++.
C
4
star
36

josephwilk.github.io

A place for pretty pictures and noises without detailed explanations.
HTML
3
star
37

fake_execution

Fake out execution in Ruby and test what was executed
Ruby
3
star
38

patterns

Collection of patterns from workshops
3
star
39

codemash2014

Making noise, that is definitely sound and might also scrap by as music
Clojure
3
star
40

fluxtone

An experiment looking at an OSC layer for Overtone <-> Fluxus
Clojure
3
star
41

software-craftsmanship-katas

Katas and source code. Experiments with different styles of coding and testing.
Ruby
2
star
42

dotfiles

Joseph Wilk's dotfiles
Shell
2
star
43

aocny

Ruby
1
star
44

vim-cucumber

Vim Runtime files for Cucumber features
Vim Script
1
star
45

midi-mash

Do the midi mash.
Clojure
1
star
46

overtone.device.monome

Clojure Experiments with an infinite plane projected onto a Monome with movement x,y
Clojure
1
star
47

prometheus-clj

Clojure
1
star
48

alice

1
star
49

overtone-midi-bug

Investigating problem with midi devices freezing.
Clojure
1
star
50

code-sounds

Like code smells only louder
Clojure
1
star
51

stereotype-clj

stereotype-clj now lives here: https://github.com/josephwilk/stereotype
1
star
52

raptor_demo

Demo of raptor
Ruby
1
star
53

fujin

Clojure
1
star
54

sample-meta

Mining data on samples using sox/aubio
Clojure
1
star
55

fake-ns

1
star
56

clj-dirt

Bindings over the DIRT sample pack used in Tidal
1
star
57

clojure-horde3d

Experiments with Clojure and Horde3d Games/Graphics engine
Clojure
1
star
58

aoc

Ruby
1
star
59

macro_tools

Macro tools for Elixir
Elixir
1
star
60

poetic-computation

Exploring code as an art material
1
star
61

spa2011

Cucumber examples used in workshop at SPA2011
1
star