miso 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/LICENSE +20 -0
  2. data/README +55 -0
  3. data/Rakefile +54 -0
  4. data/TODO +2 -0
  5. data/VERSION +1 -0
  6. data/html/classes/Miso.html +133 -0
  7. data/html/classes/Miso/Factory.html +278 -0
  8. data/html/classes/Miso/Image.html +394 -0
  9. data/html/classes/Miso/Processor.html +379 -0
  10. data/html/classes/Miso/Processor/CoreImage.html +246 -0
  11. data/html/classes/Miso/Processor/ImageMagick.html +345 -0
  12. data/html/classes/Miso/Processor/NotImplementedError.html +111 -0
  13. data/html/created.rid +1 -0
  14. data/html/files/LICENSE.html +133 -0
  15. data/html/files/README.html +156 -0
  16. data/html/files/lib/miso/factory_rb.html +101 -0
  17. data/html/files/lib/miso/image_rb.html +101 -0
  18. data/html/files/lib/miso/processor/core_image_rb.html +108 -0
  19. data/html/files/lib/miso/processor/image_magick_rb.html +110 -0
  20. data/html/files/lib/miso/processor_rb.html +101 -0
  21. data/html/files/lib/miso_rb.html +101 -0
  22. data/html/fr_class_index.html +33 -0
  23. data/html/fr_file_index.html +34 -0
  24. data/html/fr_method_index.html +62 -0
  25. data/html/index.html +24 -0
  26. data/html/rdoc-style.css +208 -0
  27. data/lib/miso.rb +5 -0
  28. data/lib/miso/factory.rb +53 -0
  29. data/lib/miso/image.rb +51 -0
  30. data/lib/miso/processor.rb +61 -0
  31. data/lib/miso/processor/core_image.rb +27 -0
  32. data/lib/miso/processor/image_magick.rb +59 -0
  33. data/spec/api/factory_spec.rb +31 -0
  34. data/spec/api/image_spec.rb +115 -0
  35. data/spec/api/processor/image_magick_spec.rb +22 -0
  36. data/spec/api/processor_spec.rb +41 -0
  37. data/spec/fixtures/120x100.png +0 -0
  38. data/spec/start.rb +30 -0
  39. metadata +97 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009
2
+ Manfred Stienstra, Fingertips <manfred@fngtps.com>
3
+ Eloy Duran, Fingertips <eloy@fngtps.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,55 @@
1
+ (...) Miso
2
+
3
+ Miso is a unified API for simple image operations commonly used on the web. It
4
+ provides backends for often used graphic libraries, but it's also pretty easy
5
+ to plug in your own backend.
6
+
7
+ A unified API is helpful when you run your code on a number of different boxes
8
+ and architectures. For instance, you could develop your web application on your
9
+ Mac with the Core Image backend [1] and deploy to your Linux server with an
10
+ ImageMagick backend. You could even have the API talk to your custom
11
+ distributed image processing backend.
12
+
13
+ [1] Note how this means you will never have to install ImageMagick again (;
14
+
15
+
16
+ : INSTALL
17
+
18
+ $ gem install miso --source http://gemcutter.org
19
+
20
+
21
+ : EXAMPLES
22
+
23
+ Miso can be used in three different ways, each useful in different situations.
24
+
25
+ 1. For the quick crop
26
+
27
+ Miso::Image.crop('input.jpg', 'output.jpg', 120, 100)
28
+
29
+ 2. For the elaborate business logic
30
+
31
+ @image = Miso::Image.new('input.jpg')
32
+ @image.crop(120, 100) if options[:crop]
33
+ @image.fit(120, 100) if options[:fit]
34
+ @image.write('output.jpg')
35
+
36
+ 3. As an option
37
+
38
+ class Attachment
39
+ has_variant :avatar,
40
+ :processor => Miso::Image.factory.crop(120, 100).fit(60, 40)
41
+ end
42
+
43
+ Which works like this;
44
+
45
+ factory = Miso::Image.factory.crop(123, 456)
46
+ factory.apply('input.jpg', 'output.jpg')
47
+
48
+ But wait, there is more! Read the API documentation for more goodies.
49
+
50
+
51
+ : SUPPORTED BACKENDS
52
+
53
+ Currently supported backends are: Core Image and ImageMagick, because those
54
+ are the ones we use. If you want to contribute backends we're happy to
55
+ accept patches!
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake/rdoctask'
3
+
4
+ desc "Run all specs by default"
5
+ task :default => :spec
6
+
7
+ namespace :spec do
8
+ desc "Run all API specs"
9
+ task :api do
10
+ Dir[File.dirname(__FILE__) + '/spec/api/**/*_spec.rb'].each do |file|
11
+ load file
12
+ end
13
+ end
14
+
15
+ desc "Run all functional specs"
16
+ task :functional do
17
+ Dir[File.dirname(__FILE__) + '/spec/functional/*_spec.rb'].each do |file|
18
+ load file
19
+ end
20
+ end
21
+ end
22
+
23
+ desc "Run all specs"
24
+ task :spec => [:'spec:api', :'spec:functional'] do
25
+ end
26
+
27
+ namespace :docs do
28
+ Rake::RDocTask.new(:generate) do |rd|
29
+ rd.main = "README"
30
+ rd.rdoc_files.include("README", "LICENSE", "lib/**/*.rb")
31
+ rd.options << "--all" << "--charset" << "utf-8"
32
+ end
33
+ end
34
+
35
+ begin
36
+ require 'jeweler'
37
+ Jeweler::Tasks.new do |s|
38
+ s.name = "miso"
39
+ s.homepage = "http://github.com/Fingertips/miso"
40
+ s.email = ["eloy@fngtps.com", "manfred@fngtps.com"]
41
+ s.authors = ["Eloy Duran", "Manfred Stienstra"]
42
+ s.summary = s.description = "Miso is a unified API for simple image operations commonly used on the web."
43
+ s.files = FileList['**/**'] # tmp until we've patched Jeweler to be able to easily add files to defaults
44
+ end
45
+ rescue LoadError
46
+ end
47
+
48
+ begin
49
+ require 'jewelry_portfolio/tasks'
50
+ JewelryPortfolio::Tasks.new do |p|
51
+ p.account = 'Fingertips'
52
+ end
53
+ rescue LoadError
54
+ end
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ - Add Miso::Image#add(image, 10, 10), which adds another image on top of the image. This should be implemented by the processor as well.
2
+ - Add Miso::Image#watermark(image, :southwest, 10, 10), which uses Miso::Image#add to add an image in one of the corners.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,133 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Miso</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Miso</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/miso/factory_rb.html">
59
+ lib/miso/factory.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/miso/image_rb.html">
63
+ lib/miso/image.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/miso/processor/core_image_rb.html">
67
+ lib/miso/processor/core_image.rb
68
+ </a>
69
+ <br />
70
+ <a href="../files/lib/miso/processor/image_magick_rb.html">
71
+ lib/miso/processor/image_magick.rb
72
+ </a>
73
+ <br />
74
+ <a href="../files/lib/miso/processor_rb.html">
75
+ lib/miso/processor.rb
76
+ </a>
77
+ <br />
78
+ <a href="../files/lib/miso_rb.html">
79
+ lib/miso.rb
80
+ </a>
81
+ <br />
82
+ </td>
83
+ </tr>
84
+
85
+ </table>
86
+ </div>
87
+ <!-- banner header -->
88
+
89
+ <div id="bodyContent">
90
+
91
+
92
+
93
+ <div id="contextContent">
94
+
95
+
96
+
97
+ </div>
98
+
99
+
100
+ </div>
101
+
102
+
103
+ <!-- if includes -->
104
+
105
+ <div id="section">
106
+
107
+ <div id="class-list">
108
+ <h3 class="section-bar">Classes and Modules</h3>
109
+
110
+ Class <a href="Miso/Factory.html" class="link">Miso::Factory</a><br />
111
+ Class <a href="Miso/Image.html" class="link">Miso::Image</a><br />
112
+ Class <a href="Miso/Processor.html" class="link">Miso::Processor</a><br />
113
+
114
+ </div>
115
+
116
+
117
+
118
+
119
+
120
+
121
+
122
+ <!-- if method_list -->
123
+
124
+
125
+ </div>
126
+
127
+
128
+ <div id="validator-badges">
129
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
130
+ </div>
131
+
132
+ </body>
133
+ </html>
@@ -0,0 +1,278 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Class: Miso::Factory</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Class</strong></td>
53
+ <td class="class-name-in-header">Miso::Factory</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/miso/factory_rb.html">
59
+ lib/miso/factory.rb
60
+ </a>
61
+ <br />
62
+ </td>
63
+ </tr>
64
+
65
+ <tr class="top-aligned-row">
66
+ <td><strong>Parent:</strong></td>
67
+ <td>
68
+ Object
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+ <div id="description">
82
+ <p>
83
+ A <a href="Factory.html">Miso::Image::Factory</a> can be used to define
84
+ multiple operations which are to be applied to an image.
85
+ </p>
86
+ <p>
87
+ A typical use case would be:
88
+ </p>
89
+ <pre>
90
+ class Member &lt; ActiveRecord::Base
91
+ has_variant :avatar, :processor =&gt; Miso::Image.factory.crop(123, 456).watermark(WATERMARK, :southwest, 10, 10)
92
+ end
93
+ </pre>
94
+ <p>
95
+ In this example, the resulting <a href="Factory.html">Miso::Factory</a>
96
+ instance would be used by the attachment library to <a
97
+ href="Factory.html#M000026">apply</a> the operations. Eg:
98
+ </p>
99
+ <pre>
100
+ module HasVariant
101
+ def process_variant(name)
102
+ variant = self.class.variants[name]
103
+ variant.processor.apply(upload_file, output_file)
104
+ end
105
+ end
106
+ </pre>
107
+
108
+ </div>
109
+
110
+
111
+ </div>
112
+
113
+ <div id="method-list">
114
+ <h3 class="section-bar">Methods</h3>
115
+
116
+ <div class="name-list">
117
+ <a href="#M000026">apply</a>&nbsp;&nbsp;
118
+ <a href="#M000023">crop</a>&nbsp;&nbsp;
119
+ <a href="#M000025">crop_fitting</a>&nbsp;&nbsp;
120
+ <a href="#M000024">fit</a>&nbsp;&nbsp;
121
+ <a href="#M000022">new</a>&nbsp;&nbsp;
122
+ </div>
123
+ </div>
124
+
125
+ </div>
126
+
127
+
128
+ <!-- if includes -->
129
+
130
+ <div id="section">
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+ <!-- if method_list -->
140
+ <div id="methods">
141
+ <h3 class="section-bar">Public Class methods</h3>
142
+
143
+ <div id="method-M000022" class="method-detail">
144
+ <a name="M000022"></a>
145
+
146
+ <div class="method-heading">
147
+ <a href="#M000022" class="method-signature">
148
+ <span class="method-name">new</span><span class="method-args">(processor_class = Processor.processor_class)</span>
149
+ </a>
150
+ </div>
151
+
152
+ <div class="method-description">
153
+ <p><a class="source-toggle" href="#"
154
+ onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
155
+ <div class="method-source-code" id="M000022-source">
156
+ <pre>
157
+ <span class="ruby-comment cmt"># File lib/miso/factory.rb, line 27</span>
158
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">processor_class</span> = <span class="ruby-constant">Processor</span>.<span class="ruby-identifier">processor_class</span>)
159
+ <span class="ruby-ivar">@processor_class</span> = <span class="ruby-identifier">processor_class</span>
160
+ <span class="ruby-ivar">@operations</span> = []
161
+ <span class="ruby-keyword kw">end</span>
162
+ </pre>
163
+ </div>
164
+ </div>
165
+ </div>
166
+
167
+ <h3 class="section-bar">Public Instance methods</h3>
168
+
169
+ <div id="method-M000026" class="method-detail">
170
+ <a name="M000026"></a>
171
+
172
+ <div class="method-heading">
173
+ <a href="#M000026" class="method-signature">
174
+ <span class="method-name">apply</span><span class="method-args">(input_file, output_file)</span>
175
+ </a>
176
+ </div>
177
+
178
+ <div class="method-description">
179
+ <p><a class="source-toggle" href="#"
180
+ onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
181
+ <div class="method-source-code" id="M000026-source">
182
+ <pre>
183
+ <span class="ruby-comment cmt"># File lib/miso/factory.rb, line 47</span>
184
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">apply</span>(<span class="ruby-identifier">input_file</span>, <span class="ruby-identifier">output_file</span>)
185
+ <span class="ruby-identifier">image</span> = <span class="ruby-constant">Image</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">input_file</span>, <span class="ruby-ivar">@processor_class</span>)
186
+ <span class="ruby-ivar">@operations</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">method</span>, <span class="ruby-identifier">args</span><span class="ruby-operator">|</span> <span class="ruby-identifier">image</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">method</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>) }
187
+ <span class="ruby-identifier">image</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">output_file</span>)
188
+ <span class="ruby-keyword kw">end</span>
189
+ </pre>
190
+ </div>
191
+ </div>
192
+ </div>
193
+
194
+ <div id="method-M000023" class="method-detail">
195
+ <a name="M000023"></a>
196
+
197
+ <div class="method-heading">
198
+ <a href="#M000023" class="method-signature">
199
+ <span class="method-name">crop</span><span class="method-args">(width, height)</span>
200
+ </a>
201
+ </div>
202
+
203
+ <div class="method-description">
204
+ <p><a class="source-toggle" href="#"
205
+ onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
206
+ <div class="method-source-code" id="M000023-source">
207
+ <pre>
208
+ <span class="ruby-comment cmt"># File lib/miso/factory.rb, line 32</span>
209
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">crop</span>(<span class="ruby-identifier">width</span>, <span class="ruby-identifier">height</span>)
210
+ <span class="ruby-ivar">@operations</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">:crop</span>, [<span class="ruby-identifier">width</span>, <span class="ruby-identifier">height</span>]]
211
+ <span class="ruby-keyword kw">self</span>
212
+ <span class="ruby-keyword kw">end</span>
213
+ </pre>
214
+ </div>
215
+ </div>
216
+ </div>
217
+
218
+ <div id="method-M000025" class="method-detail">
219
+ <a name="M000025"></a>
220
+
221
+ <div class="method-heading">
222
+ <a href="#M000025" class="method-signature">
223
+ <span class="method-name">crop_fitting</span><span class="method-args">(width, heigth)</span>
224
+ </a>
225
+ </div>
226
+
227
+ <div class="method-description">
228
+ <p><a class="source-toggle" href="#"
229
+ onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
230
+ <div class="method-source-code" id="M000025-source">
231
+ <pre>
232
+ <span class="ruby-comment cmt"># File lib/miso/factory.rb, line 42</span>
233
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">crop_fitting</span>(<span class="ruby-identifier">width</span>, <span class="ruby-identifier">heigth</span>)
234
+ <span class="ruby-ivar">@operations</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">:crop_fitting</span>, [<span class="ruby-identifier">width</span>, <span class="ruby-identifier">height</span>]]
235
+ <span class="ruby-keyword kw">self</span>
236
+ <span class="ruby-keyword kw">end</span>
237
+ </pre>
238
+ </div>
239
+ </div>
240
+ </div>
241
+
242
+ <div id="method-M000024" class="method-detail">
243
+ <a name="M000024"></a>
244
+
245
+ <div class="method-heading">
246
+ <a href="#M000024" class="method-signature">
247
+ <span class="method-name">fit</span><span class="method-args">(width, height)</span>
248
+ </a>
249
+ </div>
250
+
251
+ <div class="method-description">
252
+ <p><a class="source-toggle" href="#"
253
+ onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
254
+ <div class="method-source-code" id="M000024-source">
255
+ <pre>
256
+ <span class="ruby-comment cmt"># File lib/miso/factory.rb, line 37</span>
257
+ <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">fit</span>(<span class="ruby-identifier">width</span>, <span class="ruby-identifier">height</span>)
258
+ <span class="ruby-ivar">@operations</span> <span class="ruby-operator">&lt;&lt;</span> [<span class="ruby-identifier">:fit</span>, [<span class="ruby-identifier">width</span>, <span class="ruby-identifier">height</span>]]
259
+ <span class="ruby-keyword kw">self</span>
260
+ <span class="ruby-keyword kw">end</span>
261
+ </pre>
262
+ </div>
263
+ </div>
264
+ </div>
265
+
266
+
267
+ </div>
268
+
269
+
270
+ </div>
271
+
272
+
273
+ <div id="validator-badges">
274
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
275
+ </div>
276
+
277
+ </body>
278
+ </html>