dynamic_image 0.9.0 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +68 -18
- data/VERSION +1 -1
- data/app/models/image.rb +7 -2
- data/dynamic_image.gemspec +2 -2
- data/lib/dynamic_image/active_record_extensions.rb +3 -0
- data/lib/dynamic_image/helper.rb +9 -23
- data/lib/dynamic_image.rb +1 -0
- data/lib/generators/dynamic_image/templates/migrations/create_images.rb +0 -1
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
= DynamicImage
|
2
2
|
|
3
|
-
DynamicImage is a Rails plugin
|
4
|
-
and processing
|
3
|
+
DynamicImage is a Rails plugin that simplifies image uploading and processing.
|
4
|
+
No configuration is necessary, as resizing and processing is done on demand and
|
5
|
+
cached rather than on upload.
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
Note: This version is currently Rails 3 specific, although the final 1.0
|
8
|
+
version will also be compatible with 2.x.
|
8
9
|
|
9
10
|
|
10
|
-
== Installation
|
11
|
+
== Installation
|
11
12
|
|
12
13
|
Install the gem:
|
13
14
|
|
@@ -23,37 +24,86 @@ Do the migrations:
|
|
23
24
|
rake db:migrate
|
24
25
|
|
25
26
|
|
26
|
-
== Getting started
|
27
|
+
== Getting started
|
27
28
|
|
28
|
-
|
29
|
+
Let's create a model with an image:
|
29
30
|
|
30
31
|
class User
|
31
|
-
belongs_to_image :
|
32
|
+
belongs_to_image :mugshot
|
32
33
|
end
|
33
34
|
|
34
|
-
|
35
|
+
Uploading files is pretty straightforward, just add a <tt>file_field</tt>
|
36
|
+
to your form and update your record as usual:
|
35
37
|
|
36
38
|
<%= form_for @user, :html => {:multipart => true} do |f| %>
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
Name: <%= f.text_field :name %>
|
40
|
+
Mugshot: <%= f.file_field :mugshot %>
|
41
|
+
<%= submit_tag "Save" %>
|
40
42
|
<% end %>
|
41
43
|
|
42
|
-
|
44
|
+
You can now use the <tt>dynamic_image_tag</tt> helper to show off your
|
45
|
+
new image:
|
43
46
|
|
44
|
-
|
45
|
-
|
47
|
+
<% if @user.mugshot? %>
|
48
|
+
<%= dynamic_image_tag @user.profile_picture, :size => '64x64' %>
|
49
|
+
<% end %>
|
50
|
+
|
51
|
+
|
52
|
+
== Filters
|
46
53
|
|
54
|
+
I'm cleaning up the filters syntax, watch this space.
|
47
55
|
|
48
|
-
|
56
|
+
|
57
|
+
== Technical
|
58
|
+
|
59
|
+
The original master files are stored in the file system and identified a
|
60
|
+
SHA-1 hash of the contents. If you're familiar with the internal workings
|
61
|
+
of git, this should seem familiar.
|
49
62
|
|
50
63
|
Processing images on the fly is expensive. Therefore, page caching is enabled
|
51
64
|
by default, even in development mode. To disable page caching, add the following
|
52
|
-
line in your initializers
|
65
|
+
line in your initializers:
|
53
66
|
|
54
67
|
DynamicImage.page_caching = false
|
55
68
|
|
69
|
+
|
70
|
+
== History
|
71
|
+
|
72
|
+
DynamicImage was originally created in early 2006 to handle images
|
73
|
+
for the Pages CMS. It was later extracted as a Rails Engine for Rails
|
74
|
+
1.2 in 2007, which also marked the first public release as
|
75
|
+
dynamic_image_engine.
|
76
|
+
|
77
|
+
The API has remained more or less unchanged, but the internal workings
|
78
|
+
have been refactored a few times over the years, most notably dropping
|
79
|
+
the Engines dependency and transitioning from database storage to file
|
80
|
+
system.
|
81
|
+
|
82
|
+
The current version is based on an internal branch targeting Rails
|
83
|
+
2.3, and modified to work as a Rails 3 plugin. It's not directly
|
84
|
+
compatible with earlier versions, but upgrading shouldn't be more
|
85
|
+
trouble than migrating the files out of the database.
|
86
|
+
|
87
|
+
|
56
88
|
== Copyright
|
57
89
|
|
58
|
-
Copyright © 2006-2010 Inge Jørgensen.
|
90
|
+
Copyright © 2006-2010 Inge Jørgensen.
|
59
91
|
|
92
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
93
|
+
a copy of this software and associated documentation files (the
|
94
|
+
"Software"), to deal in the Software without restriction, including
|
95
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
96
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
97
|
+
permit persons to whom the Software is furnished to do so, subject to
|
98
|
+
the following conditions:
|
99
|
+
|
100
|
+
The above copyright notice and this permission notice shall be
|
101
|
+
included in all copies or substantial portions of the Software.
|
102
|
+
|
103
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
104
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
105
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
106
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
107
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
108
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
109
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.3
|
data/app/models/image.rb
CHANGED
@@ -21,10 +21,15 @@ class Image < ActiveRecord::Base
|
|
21
21
|
image.crop_start = "0x0"
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
# Create the binary from an image file.
|
26
26
|
def imagefile=(image_file)
|
27
|
-
|
27
|
+
if image_file.kind_of?(String) && image_file =~ /^(ht|f)tps?:\/\//
|
28
|
+
self.filename = File.basename(image_file)
|
29
|
+
image_file = open(image_file)
|
30
|
+
else
|
31
|
+
self.filename = image_file.original_filename rescue File.basename(image_file.path)
|
32
|
+
end
|
28
33
|
self.content_type = image_file.content_type.chomp rescue "image/"+image_file.path.split(/\./).last.downcase.gsub(/jpg/,"jpeg") # ugly hack
|
29
34
|
set_image_data(image_file.read)
|
30
35
|
end
|
data/dynamic_image.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dynamic_image}
|
8
|
-
s.version = "0.9.
|
8
|
+
s.version = "0.9.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Inge J\303\270rgensen"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-20}
|
13
13
|
s.email = %q{inge@elektronaut.no}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -43,6 +43,9 @@ module DynamicImage
|
|
43
43
|
self.associated_#{association_id} = img_obj
|
44
44
|
end
|
45
45
|
end
|
46
|
+
def #{association_id}?
|
47
|
+
(self.#{association_id} && self.#{association_id}.data?) ? true : false
|
48
|
+
end
|
46
49
|
end_eval
|
47
50
|
|
48
51
|
send :include, DynamicImage::ActiveRecordExtensions::InstanceMethods
|
data/lib/dynamic_image/helper.rb
CHANGED
@@ -74,36 +74,22 @@ module DynamicImage
|
|
74
74
|
end
|
75
75
|
|
76
76
|
# Returns an image tag for the provided image model, works similar to the rails <tt>image_tag</tt> helper.
|
77
|
-
# The <tt>alt</tt> tag is set to the image title unless explicitly provided.
|
78
77
|
#
|
79
78
|
# The following options are supported (the rest will be forwarded to <tt>image_tag</tt>):
|
80
79
|
#
|
81
|
-
#
|
80
|
+
# * :size - Resize the image to fit these proportions. Size is given as a string with the format
|
82
81
|
# '100x100'. Either dimension can be omitted, for example: '100x'
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
82
|
+
# * :crop - Crop the image to the size given. (Boolean, default: <tt>false</tt>)
|
83
|
+
# * :no_size_attr - Do not include width and height attributes in the image tag. (Boolean, default: false)
|
84
|
+
# * :filterset - Apply the given filterset to the image
|
86
85
|
#
|
87
|
-
#
|
86
|
+
# ==== Examples
|
88
87
|
#
|
89
|
-
#
|
90
|
-
#
|
88
|
+
# dynamic_image_tag(@image) # Original image
|
89
|
+
# dynamic_image_tag(@image, :size => "100x") # Will be 100px wide
|
90
|
+
# dynamic_image_tag(@image, :size => "100x100") # Will fit within 100x100
|
91
|
+
# dynamic_image_tag(@image, :size => "100x100", :crop => true) # Will be cropped to 100x100
|
91
92
|
#
|
92
|
-
# Tag for image, rescaled to fit within 100x100 (size will be 100x100 or smaller):
|
93
|
-
# <%= dynamic_image_tag(@image, :size => "100x100") %>
|
94
|
-
#
|
95
|
-
# Tag for image, cropped and rescaled to 100x100 (size will be 100x100 in all cases):
|
96
|
-
# <%= dynamic_image_tag(@image, :size => "100x100", :crop => true) %>
|
97
|
-
#
|
98
|
-
# Tag for image with a filter set applied:
|
99
|
-
# <%= dynamic_image_tag(@image, :size => "100x100", :filterset => @filterset) %>
|
100
|
-
#
|
101
|
-
# Tag for image with a named filter set applied:
|
102
|
-
# <%= dynamic_image_tag(@image, :size => "100x100", :filterset => "thumbnails") %>
|
103
|
-
#
|
104
|
-
# Tag for image without the width/height attributes, and with a custom alt attribute
|
105
|
-
# <%= dynamic_image_tag(@image, :size => "100x100", :no_size_attr => true, :alt => "Thumbnail for post" %>
|
106
|
-
|
107
93
|
def dynamic_image_tag(image, options = {})
|
108
94
|
parsed_options = dynamic_image_options(image, options)
|
109
95
|
image_tag(parsed_options[:url], parsed_options[:options] ).gsub(/\?[\d]+/,'')
|
data/lib/dynamic_image.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 3
|
9
|
+
version: 0.9.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Inge J\xC3\xB8rgensen"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-20 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|