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.
@@ -53,11 +53,22 @@ module RailsMagick
53
53
  end
54
54
 
55
55
  # Generates a thumbnail. Ruthless about cropping.
56
- def self.create_thumbnail(infile, outfile, width, height, quality = 80)
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
 
@@ -1,3 +1,3 @@
1
1
  module RailsMagick
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -92,3 +92,28 @@ Connecting to database specified by database.yml
92
92
   (0.1ms) rollback transaction
93
93
   (0.0ms) begin transaction
94
94
   (0.1ms) rollback transaction
95
+ Connecting to database specified by database.yml
96
+  (0.2ms) begin transaction
97
+  (0.1ms) rollback transaction
98
+  (0.0ms) begin transaction
99
+  (0.1ms) rollback transaction
100
+  (0.0ms) begin transaction
101
+  (0.1ms) rollback transaction
102
+ Connecting to database specified by database.yml
103
+  (0.2ms) begin transaction
104
+  (0.1ms) rollback transaction
105
+  (0.0ms) begin transaction
106
+  (0.7ms) rollback transaction
107
+  (0.0ms) begin transaction
108
+  (0.1ms) rollback transaction
109
+  (0.0ms) begin transaction
110
+  (0.1ms) rollback transaction
111
+ Connecting to database specified by database.yml
112
+  (0.2ms) begin transaction
113
+  (0.1ms) rollback transaction
114
+  (0.0ms) begin transaction
115
+  (0.1ms) rollback transaction
116
+  (0.0ms) begin transaction
117
+  (0.1ms) rollback transaction
118
+  (0.0ms) begin transaction
119
+  (0.1ms) rollback transaction
Binary file
@@ -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.7
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-04 00:00:00.000000000 Z
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