has_image 0.2.3 → 0.3.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.
- data/CHANGELOG +12 -0
- data/README.textile +193 -0
- data/Rakefile +3 -1
- data/init.rb +1 -1
- data/lib/has_image.rb +152 -104
- data/lib/has_image/processor.rb +58 -31
- data/lib/has_image/storage.rb +72 -45
- data/test/storage_test.rb +44 -2
- data/test_rails/complex_pic_test.rb +42 -0
- data/test_rails/pic_test.rb +72 -9
- data/test_rails/schema.rb +7 -1
- data/test_rails/test_helper.rb +1 -3
- metadata +6 -9
- data/README +0 -161
- data/test_rails/pic.rb +0 -3
data/test_rails/schema.rb
CHANGED
data/test_rails/test_helper.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
|
-
|
3
1
|
ENV['RAILS_ENV'] = 'test'
|
4
2
|
|
5
3
|
require 'test/unit'
|
6
4
|
require File.expand_path(File.join(File.dirname(__FILE__), '/../../../../config/environment.rb'))
|
5
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
|
7
6
|
require 'active_record/fixtures'
|
8
7
|
require 'action_controller/test_process'
|
9
8
|
|
@@ -51,4 +50,3 @@ class Test::Unit::TestCase #:nodoc:
|
|
51
50
|
self.use_instantiated_fixtures = false
|
52
51
|
|
53
52
|
end
|
54
|
-
require 'pic'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-10-
|
12
|
+
date: 2008-10-22 00:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -28,15 +28,13 @@ executables: []
|
|
28
28
|
|
29
29
|
extensions: []
|
30
30
|
|
31
|
-
extra_rdoc_files:
|
32
|
-
|
33
|
-
- CHANGELOG
|
34
|
-
- FAQ
|
31
|
+
extra_rdoc_files: []
|
32
|
+
|
35
33
|
files:
|
36
34
|
- CHANGELOG
|
37
35
|
- FAQ
|
38
36
|
- MIT-LICENSE
|
39
|
-
- README
|
37
|
+
- README.textile
|
40
38
|
- init.rb
|
41
39
|
- lib/has_image.rb
|
42
40
|
- lib/has_image/processor.rb
|
@@ -48,7 +46,6 @@ homepage: http://randomba.org
|
|
48
46
|
post_install_message:
|
49
47
|
rdoc_options:
|
50
48
|
- --main
|
51
|
-
- README
|
52
49
|
- --inline-source
|
53
50
|
- --line-numbers
|
54
51
|
require_paths:
|
@@ -77,8 +74,8 @@ test_files:
|
|
77
74
|
- test_rails/fixtures/bad_image.jpg
|
78
75
|
- test_rails/fixtures/image.jpg
|
79
76
|
- test_rails/fixtures/image.png
|
80
|
-
- test_rails/pic.rb
|
81
77
|
- test_rails/pic_test.rb
|
78
|
+
- test_rails/complex_pic_test.rb
|
82
79
|
- test_rails/schema.rb
|
83
80
|
- test_rails/test_helper.rb
|
84
81
|
- test/processor_test.rb
|
data/README
DELETED
@@ -1,161 +0,0 @@
|
|
1
|
-
= HasImage[http://github.com/norman/has_image] -- Image attachment gem/plugin for Ruby on Rails
|
2
|
-
|
3
|
-
HasImage[http://github.com/norman/has_image] was created as a smaller,
|
4
|
-
simpler, lighter alternative to
|
5
|
-
attachment_fu[http://github.com/technoweenie/attachment_fu] for applications
|
6
|
-
that need to handle uploaded images.
|
7
|
-
|
8
|
-
It creates only one database record per image, requires only one column in
|
9
|
-
your model, and creates great-looking fixed-dimension thumbnails by using
|
10
|
-
{ImageMagick's}[http://www.imagemagick.org/]
|
11
|
-
resize[http://www.imagemagick.org/script/command-line-options.php#resize],
|
12
|
-
crop[http://www.imagemagick.org/script/command-line-options.php#crop] and
|
13
|
-
gravity[http://www.imagemagick.org/script/command-line-options.php#gravity]
|
14
|
-
functions.
|
15
|
-
|
16
|
-
Some typical use cases are: websites that want to create photo galleries with
|
17
|
-
fixed-dimension thumbnails, or that want to store user profile pictures
|
18
|
-
without creating a separate model for the images.
|
19
|
-
|
20
|
-
It supports only filesystem storage, and uses only MiniMagick[http://github.com/probablycorey/mini_magick] to process
|
21
|
-
images. However, the codebase is very small, simple, readable, and hackable.
|
22
|
-
So it should be easy to modify or enhance its functionality with different
|
23
|
-
storage or processor options.
|
24
|
-
|
25
|
-
== Another image attachment library? Why?
|
26
|
-
|
27
|
-
<em>The three chief virtues of a programmer are: Laziness, Impatience and Hubris.</em> - {Larry Wall}[http://en.wikipedia.org/wiki/Larry_Wall]
|
28
|
-
|
29
|
-
Attachment_fu is too large and general for some of the places I want to use
|
30
|
-
images. I sometimes found myself writing more code to hack attachment_fu than
|
31
|
-
it took to create this gem. In fact, most of the code here has been plucked
|
32
|
-
from my various projects that use attachment_fu.
|
33
|
-
|
34
|
-
The other image attachment libraries I found fell short of my needs for
|
35
|
-
various other reasons, so I decided to roll my own.
|
36
|
-
|
37
|
-
== Examples
|
38
|
-
|
39
|
-
Point-and-drool use case. It's probably not what you want, but it may be
|
40
|
-
useful for bootstrapping.
|
41
|
-
|
42
|
-
class Member < ActiveRecord::Base
|
43
|
-
has_image
|
44
|
-
end
|
45
|
-
|
46
|
-
Single image, no thumbnails, with some size limits:
|
47
|
-
|
48
|
-
class Picture < ActiveRecord::Base
|
49
|
-
has_image :resize_to => "200x200",
|
50
|
-
:max_size => 3.megabytes,
|
51
|
-
:min_size => 4.kilobytes
|
52
|
-
end
|
53
|
-
|
54
|
-
Image with some thumbnails:
|
55
|
-
|
56
|
-
class Photo < ActiveRecord::Base
|
57
|
-
has_image :resize_to => "640x480",
|
58
|
-
:thumbnails => {
|
59
|
-
:square => "200x200",
|
60
|
-
:medium => "320x240"
|
61
|
-
},
|
62
|
-
:max_size => 3.megabytes,
|
63
|
-
:min_size => 4.kilobytes
|
64
|
-
end
|
65
|
-
|
66
|
-
It also provides a view helper to make displaying the images extremely simple:
|
67
|
-
|
68
|
-
<%= image_tag_for(@photo) # show the full-sized image %>
|
69
|
-
<%= image_tag_for(@photo, :thumb => :square) # show the square thumbnail %>
|
70
|
-
|
71
|
-
The image_tag_for helper calls Rails' image_tag, so you can pass in all the
|
72
|
-
regular options to set the alt property, CSS class, etc:
|
73
|
-
|
74
|
-
<%= image_tag_for(@photo, :alt => "my cool picture", :class => "photo") %>
|
75
|
-
|
76
|
-
Setting up forms for has_image is simple, too:
|
77
|
-
|
78
|
-
<% form_for(@photo, :html => {:multipart => true}) do |f| %>
|
79
|
-
<p>
|
80
|
-
<%= f.label :image_data %>
|
81
|
-
<%= f.file_field :image_data %>
|
82
|
-
</p>
|
83
|
-
<p>
|
84
|
-
<%= f.submit %>
|
85
|
-
</p>
|
86
|
-
<% end %>
|
87
|
-
|
88
|
-
== Getting it
|
89
|
-
|
90
|
-
Has image can be installed as a gem, or as a Rails plugin. Gem installation
|
91
|
-
is easiest, and recommended:
|
92
|
-
|
93
|
-
gem install has_image
|
94
|
-
|
95
|
-
and add
|
96
|
-
|
97
|
-
require 'has_image'
|
98
|
-
|
99
|
-
to your environment.rb file.
|
100
|
-
|
101
|
-
Alternatively, you can install it as a Rails plugin:
|
102
|
-
|
103
|
-
./script plugin install git://github.com/norman/has_image.git
|
104
|
-
|
105
|
-
Rails versions before 2.1 do not support plugin installation using Git, so if
|
106
|
-
you're on 2.0 (or earlier), then please install the gem rather than the
|
107
|
-
plugin.
|
108
|
-
|
109
|
-
Then, make sure the model has a column named "has_image_file."
|
110
|
-
|
111
|
-
{Git repository}[http://github.com/norman/has_image]:
|
112
|
-
|
113
|
-
git://github.com/norman/has_image.git
|
114
|
-
|
115
|
-
== Hacking it
|
116
|
-
|
117
|
-
Don't like the way it makes images? Want to pipe the images through some
|
118
|
-
{crazy fast seam carving library written in
|
119
|
-
OCaml}[http://eigenclass.org/hiki/seam-carving-in-ocaml], or watermark them
|
120
|
-
with your corporate logo? Happiness is just a monkey-patch[http://en.wikipedia.org/wiki/Monkey_patch] away:
|
121
|
-
|
122
|
-
module HasImage
|
123
|
-
class Processor
|
124
|
-
def resize_image(size)
|
125
|
-
# your new-and-improved thumbnailer code goes here.
|
126
|
-
end
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
HasImage[http://github.com/norman/has_image] follows a philosophy of "{skinny
|
131
|
-
model, fat plugin}[http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model]."
|
132
|
-
This means that it tries to pollute your ActiveRecord model with as little
|
133
|
-
functionality as possible, so that in a sense, the model is acts like a
|
134
|
-
"controller" and the plugin like a "model" as regards the image handling
|
135
|
-
functionality. This makes it easier to test, hack, and reuse, because the
|
136
|
-
storage and processing functionality is largely independent of your model, and
|
137
|
-
of Rails.
|
138
|
-
|
139
|
-
My goal for HasImage[http://github.com/norman/has_image] is to keep it very
|
140
|
-
small. If you need *a lot* of functionality that's not here, instead of patching
|
141
|
-
this code, you will likely be better off using
|
142
|
-
attachment_fu[http://github.com/technoweenie/attachment_fu], which is much
|
143
|
-
more powerful, but also more complex.
|
144
|
-
|
145
|
-
== Bugs
|
146
|
-
|
147
|
-
Please report them on Lighthouse[http://randomba.lighthouseapp.com/projects/14674-has_image].
|
148
|
-
|
149
|
-
At the time of writing (July 2008),
|
150
|
-
HasImage[http://github.com/norman/has_image] is in its infancy. Your patches,
|
151
|
-
bug reports and withering criticism are more than welcome.
|
152
|
-
|
153
|
-
== Links
|
154
|
-
|
155
|
-
* {HasImage RDocs}[http://randomba.org/projects/has_image] (regenerated nightly)
|
156
|
-
* {HasImage on GitHub}[http://github.com/norman/has_image]
|
157
|
-
* {HasImage on Rubyforge}[http://rubyforge.org/projects/has-image/]
|
158
|
-
* {HasImage on Lighthouse}[http://randomba.lighthouseapp.com/projects/14674-has_image]
|
159
|
-
|
160
|
-
Copyright (c) 2008 {Norman Clarke}[mailto:norman@randomba.org], released under
|
161
|
-
the MIT license
|
data/test_rails/pic.rb
DELETED