• Stars
    star
    179
  • Rank 213,194 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 13 years ago
  • Updated over 8 years ago

Reviews

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

Repository Details

image manipulation as a (plugin-able) service

Magickly - image manipulation as a (plugin-able) service

Built as a practical wrapper of Imagemagick which handles caching, c/o the Dragonfly gem.

Say the base URL is the hosted version of this app, magickly.afeld.me. The image URL is appended to the query string as a src=, followed by any of the supported operations below. Multiple operations can be combined, and will be applied in order.

If no query params are provided, a simple sandbox page is displayed. Try it here:

magickly.afeld.me

More insights:

Installation

Compatible with Ruby 1.9.3, 2.0 and 2.1, and jRuby (in 1.9 mode). Requires Imagemagick >= v6.2.4.

$ gem install magickly

Running the App

A few options:

A. Run the app directly

# in the app directory:
$ gem install thin
$ thin start

The app can be accessed at http://localhost:3000.

When running as an app, Rack::Cache is used to cache generated versions of images. These cached files and metadata are stored in the tmp/ directory and will get regenerated as necessary.

B. Use as an endpoint in another Rack app

As an example, to have magickly accessible at /magickly in a Rails app:

# Gemfile
gem 'magickly', '~> 1.1'

# config/routes.rb
match '/magickly', :to => Magickly::App, :anchor => false

For more info, see Rails Routing from the Outside In or Michael Raidel's Mount Rails apps in Rails 3.

Processing Parameters

See the Dragonfly documentation for more details about the permitted geometry values.

src=url (required)

The URL of the original image.

brightness_contrast=br. x con.

brightness and contrast are percentage change, between -100 and 100. For example, to increase contrast by 20% but leave brightness unchanged, use brightness_contrast=0x20.

tanned imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&brightness_contrast=-10x50

flip=true

flipped imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&flip=true

flop=true

flopped imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&flop=true

glow=amount,softness

where amount is a float >= 1.0, and softness is an int >= 0.

glowing imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&glow=1.2,20

greyscale=true

flopped imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&greyscale=true

halftone=threshold

where threshold is a value between 0 and 100.

halftone imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&halftone=60

jcn=true

JCN imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&jcn=true

resize=geometry

resized imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&resize=100x100

rotate=degrees

rotated imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&rotate=45

saturation=percentage

percentage is the percentage of variation: a positive integer. 100 means no change. For example, to increase saturation by 50%, use saturation=150.

saturated imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&saturation=150

tilt_shift=true

tilt-shifted imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&tilt_shift=true

thumb=geometry

thumbnail of imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&thumb=200x100%23

(note: the %23 in the geometry string above is an encoded '#', which tells Dragonfly to fill the dimensions and crop)

two_color=true

two color imagemagick logo

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&two_color=true

Alternate Syntax

Some CDNs are jerks and don't respect query params on resources (ahem CLOUDFRONT ahem) when caching. To use this syntax:

  • replace the question mark that starts the query string (?) with q/
  • replace the ampersands (&) and equals signs (=) with forward slashes (/)
  • make sure the src is encoded - this can be done in Javascript with encodeURIComponent()

Therefore, instead of

http://magickly.afeld.me/?src=http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Imagemagick-logo.png/200px-Imagemagick-logo.png&thumb=200x100

the new URL would be

http://magickly.afeld.me/q/src/http%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F0%2F0d%2FImagemagick-logo.png%2F200px-Imagemagick-logo.png/thumb/200x100

Encoded Syntax

Sometimes, you just can't handle escaped entities in your URLs (Facebook's handling of OpenGraph tags, for example). In those cases, we provide a Base64 encoded syntax which is an extension of the path-based Alternate Syntax above. Once your path-based url is constructed (see "Alternate Syntax" above), simply pass everything after the q/ through Base64.urlsafe_encode or the javascript btoa() function and send it to the qe/ endpoint instead.

Therefore, instead of

http://magickly.afeld.me/q/src/http%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fthumb%2F0%2F0d%2FImagemagick-logo.png%2F200px-Imagemagick-logo.png/thumb/200x100

the new URL would be

http://magickly.afeld.me/qe/c3JjL2h0dHAlM0ElMkYlMkZ1cGxvYWQud2lraW1lZGlhLm9yZyUyRndpa2lwZWRpYSUyRmNvbW1vbnMlMkZ0aHVtYiUyRjAlMkYwZCUyRkltYWdlbWFnaWNrLWxvZ28ucG5nJTJGMjAwcHgtSW1hZ2VtYWdpY2stbG9nby5wbmcvdGh1bWIvMjAweDEwMA==

Analyzers

Magickly v1.2.0 introduces the ability to retrieve image properties via a REST API. For example, to retrieve the number of colors in the photo, visit:

magickly.afeld.me/analyze/number_of_colors?src=...

To get the list of available analyzers, visit magickly.afeld.me/analyze

Customization

In addition to the available parameters listed above, custom "shortcuts" can be created to perform arbitrary imagemagick operations. For example, to create a shortcut called resize_with_blur:

# somewhere in your app configuration, i.e. config/initializers/magickly.rb for a Rails 3 app
Magickly.dragonfly.configure do |c|
  c.job :resize_with_blur do |size|
    process :convert, "-filter Gaussian -resize #{size}"
  end
end

which can then be used with the query string ?src=...&resize_with_blur=200x. Note that magickly will pass the value of the query param to the block as a single string.

See the Dragonfly documentation for more info on "shortcuts", and the shortcuts.rb file for examples.

Disclaimer

The hosted version of the app (magickly.afeld.me) is a single app instance intended for demonstration purposes - if you are going to be making a large number of API calls to it or would like to use it in production, please let us know :-)

See Also

More Repositories

1

emoji-css

An easy way to include emoji in your HTML
JavaScript
892
star
2

backbone-nested

A plugin to make Backbone.js keep track of nested attributes - looking for maintainers! https://github.com/afeld/backbone-nested/issues/157
JavaScript
444
star
3

mustachio

automatic mustachifying of any image
Ruby
344
star
4

jsonp

DEPRECATED - A proxy to help with cross-domain requests
JavaScript
302
star
5

rails_interview_questions

A list of some baseline Rails interview questions
298
star
6

bootstrap-toc

An automatic table of contents generator, using Bootstrap 3 or 4
JavaScript
157
star
7

git-plugins

a collection of custom git commands
Shell
61
star
8

api.afeld.me

nerdiest homepage ever
Ruby
51
star
9

tricle

easy metrics reporting via email
Ruby
36
star
10

jeditable-rails

a gem to add in-place-editable fields to your Rails project
Ruby
35
star
11

python-public-policy

Python for Public Policy course
Jupyter Notebook
25
star
12

github_non_coding

a list of non-coding use cases of GitHub
Ruby
23
star
13

html_pipeline_rails

rendering views via HTML::Pipeline in Rails
Ruby
20
star
14

dotfiles

my dotfiles
Shell
17
star
15

github-find

Chrome extension for searching within a Github repo.
JavaScript
16
star
16

stringer

a project with Alex Chen and Tyler Williams for doing string drawing and plucking in Processing using the Kinect
Processing
15
star
17

jsonpanel

pretty JSON viewer jQuery plugin
CSS
12
star
18

git-setup

easy Git setup
Shell
12
star
19

teaching

a collection of materials/resources for teaching technology
10
star
20

3d-controller

demos of using a phone as a gestural interface
JavaScript
10
star
21

face_detect

a Ruby gem for face detection
Ruby
9
star
22

tfmv

proof of concept: a tool to help refactoring Terraform resources
Go
9
star
23

bike-report

messing with NYC CitiBike historical data
Ruby
8
star
24

sshkit-interactive

WIP: execute interactive commands on your servers via SSHKit
Ruby
7
star
25

mustachio-js

automatic mustachifying of any image
JavaScript
6
star
26

gh_collab

slides for "How GitHub Does Collaboration" talk
JavaScript
5
star
27

github_invite

app to enable GitHub users to easily add others to their organization teams
Ruby
5
star
28

sparkle

API for generating sparklines
Ruby
4
star
29

facial

WORK IN PROGRESS - Simple library for face detection using OpenCV
Ruby
4
star
30

spaa

Single-Page App Architecture talk
CSS
4
star
31

refactor

a command line tool to help refactor your code
Ruby
3
star
32

delivery

Continuous Delivery workshop materials
HCL
3
star
33

pose

experimenting with real-time pose detection and speech recognition for dance performance
TypeScript
3
star
34

hubot-twitter-config

WIP: configuration module for using Twitter via Hubot
CoffeeScript
3
star
35

repo-eyes

scripts to keep watch over your repositories
Ruby
2
star
36

careless

LESS rendering as a service
JavaScript
2
star
37

faacelift

JavaScript
2
star
38

tech-foundations

Columbia SPS Operations Management in IT course
JavaScript
2
star
39

compare_by

a better version of Ruby's Comparable
Ruby
2
star
40

test_to_learn

a talk about learning to code via testing
JavaScript
2
star
41

personal-security

Digital Security and Privacy for Normal People - a guide
HTML
2
star
42

practical_tdd

2
star
43

node-face

Face.com API wrapper for NodeJS
JavaScript
2
star
44

tdd_js

talk: Test-Drive Your JavaScript
JavaScript
2
star
45

data-cleaning

Data Cleaning Techniques workshop materials
Jupyter Notebook
2
star
46

filter_feeder

JavaScript
2
star
47

jekyll-git

a Jekyll plugin for retrieving data from Git
Ruby
2
star
48

geo_formatter

A JS wrapper for easier-to-work-with Google Geocoder results.
JavaScript
2
star
49

jquery-clearinput

Clears the instructions from an HTML form input on focus, replacing the text if nothing is entered.
JavaScript
2
star
50

SWICS-Fix

a little Python script to clean up some solar wind data
Python
1
star
51

flyloft

a jobs site for performing artists (a work in progress)
Ruby
1
star
52

multipass-examples

Examples on how to use Assistly's Multipass SSO
PHP
1
star
53

wedding

wedding website
HTML
1
star
54

markdown_proofer

Markdown validator gem
Ruby
1
star
55

photo-frame

[WORK IN PROGRESS] photo frame that automatically pulls from Facebook
TypeScript
1
star
56

arduino_low_battery

low battery indicator for Arduino
Arduino
1
star
57

tangle

a web page scanner to find broken links
Go
1
star
58

repowatch

JavaScript
1
star
59

threepenny

Ruby
1
star
60

ellipsis-test

test suite of plugins for handling multiline-text-overflow
1
star
61

hubot-trollbot

a hubot script that annoys your coworkers
CoffeeScript
1
star
62

paypal_form

A Radiant extension for a dynamic Paypal submission form.
Ruby
1
star
63

fontsmash

Ruby
1
star
64

temp

temperature sensor to prove my jerk of a landlord was breaking the law
Arduino
1
star
65

graffiti.js

Java
1
star
66

config_settings

a code test I did for a job application: creating a model which stores configuration settings
Ruby
1
star
67

mongo_ruby_workshop

Workshop for getting started using MongoDB with Ruby
Ruby
1
star
68

knowpickle

A site for learning things
Ruby
1
star
69

govern

automatic governance for your projects
Ruby
1
star
70

web_dev_basics

Web development workshop
PHP
1
star
71

rails-bottom-up

teaching Rails from the Bottom Up
Ruby
1
star
72

dotjunkd

my junk drawer
1
star
73

code_cruise

An app for discovering learning paths: given a set of knowledge and a goal, a self-motivated learner can find all the topics between them and that destination.
Ruby
1
star