rails_magick 0.0.7 → 0.0.8
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/lib/rails_magick.rb +12 -1
- data/lib/rails_magick/version.rb +1 -1
- data/test/dummy/log/test.log +25 -0
- data/test/files/test_thumb.jpg +0 -0
- data/test/rails_magick_test.rb +9 -0
- metadata +4 -2
data/lib/rails_magick.rb
CHANGED
@@ -53,11 +53,22 @@ module RailsMagick
|
|
53
53
|
end
|
54
54
|
|
55
55
|
# Generates a thumbnail. Ruthless about cropping.
|
56
|
-
|
56
|
+
# regenerate_thumb - if false, will check the dimensions of the incoming thumbnail and NOT regenerate the thumbnail if it is the same size. Defaults to true so that it will ruthlessly crop and overwrite the thumbnail.
|
57
|
+
def self.create_thumbnail(infile, outfile, width, height, quality = 80, regenerate_thumb = true)
|
57
58
|
if !File.exist?(infile)
|
58
59
|
raise IOError, "No such file #{file}"
|
59
60
|
end
|
60
61
|
|
62
|
+
# Check if the thumbnail is already the same width and height. Don't run if it is.
|
63
|
+
if !regenerate_thumb
|
64
|
+
info = self.identify(infile)
|
65
|
+
if info[:width] == width and info[:height] == height
|
66
|
+
# Copy the file
|
67
|
+
FileUtils.copy(infile, outfile)
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
61
72
|
# Do the convert
|
62
73
|
result = `#{CONVERT} #{infile} -resize '#{width}x#{height}^' -quality #{quality} -gravity center -extent '#{width}x#{height}' #{outfile}`
|
63
74
|
|
data/lib/rails_magick/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -92,3 +92,28 @@ Connecting to database specified by database.yml
|
|
92
92
|
[1m[35m (0.1ms)[0m rollback transaction
|
93
93
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
94
94
|
[1m[35m (0.1ms)[0m rollback transaction
|
95
|
+
Connecting to database specified by database.yml
|
96
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
97
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
98
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
99
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
100
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
101
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
102
|
+
Connecting to database specified by database.yml
|
103
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
104
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
105
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
106
|
+
[1m[35m (0.7ms)[0m rollback transaction
|
107
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
108
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
109
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
110
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
111
|
+
Connecting to database specified by database.yml
|
112
|
+
[1m[36m (0.2ms)[0m [1mbegin transaction[0m
|
113
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
114
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
115
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
116
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
117
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
118
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
119
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
Binary file
|
data/test/rails_magick_test.rb
CHANGED
@@ -53,4 +53,13 @@ class RailsMagickTest < ActiveSupport::TestCase
|
|
53
53
|
|
54
54
|
end
|
55
55
|
|
56
|
+
test "should create thumbnail same size" do
|
57
|
+
infile = "#{File.dirname(__FILE__)}/files/test_thumb.jpg"
|
58
|
+
result = RailsMagick.create_thumbnail(infile, @outfile, 100, 100, 80, false)
|
59
|
+
assert(File.exists?(@outfile))
|
60
|
+
result = RailsMagick.identify(@outfile)
|
61
|
+
assert_equal(100, result[:height])
|
62
|
+
assert_equal(100, result[:width])
|
63
|
+
end
|
64
|
+
|
56
65
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- test/dummy/README.rdoc
|
89
89
|
- test/dummy/script/rails
|
90
90
|
- test/files/test.jpg
|
91
|
+
- test/files/test_thumb.jpg
|
91
92
|
- test/rails_magick_test.rb
|
92
93
|
- test/test_helper.rb
|
93
94
|
homepage: https://github.com/ballistiq/RailsMagick
|
@@ -147,5 +148,6 @@ test_files:
|
|
147
148
|
- test/dummy/README.rdoc
|
148
149
|
- test/dummy/script/rails
|
149
150
|
- test/files/test.jpg
|
151
|
+
- test/files/test_thumb.jpg
|
150
152
|
- test/rails_magick_test.rb
|
151
153
|
- test/test_helper.rb
|