has_image 0.1.2 → 0.1.3

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 CHANGED
@@ -1,3 +1,8 @@
1
+ 2008-07-29 Norman Clarke <norman@randomba.org>
2
+
3
+ * Reverted thumbnail sorting feature - it's fast but makes terrible quality
4
+ thumbnails. It's just not worth it.
5
+
1
6
  2008-07-28 Norman Clarke <norman@randomba.org>
2
7
 
3
8
  * Added sorted thumbnail processing. This improves thumbnail generation
@@ -9,13 +9,6 @@ module HasImage
9
9
 
10
10
  class << self
11
11
 
12
- # Given a geometry string, return the maxium possible output dimensions.
13
- # For example:
14
- # area("50x50>") == 2500
15
- def area(dimensions)
16
- dimensions.split("x")[0].to_i * dimensions.split("x")[1].to_i
17
- end
18
-
19
12
  # "The form of an {extended geometry
20
13
  # string}[http://www.imagemagick.org/script/command-line-options.php?#resize] is
21
14
  # <width>x<height>{+-}<xoffset>{+-}<yoffset>{%}{!}{<}{>}"
@@ -45,7 +38,9 @@ module HasImage
45
38
  # format if necessary. The size should be a valid ImageMagick {geometry
46
39
  # string}[http://www.imagemagick.org/script/command-line-options.php#resize].
47
40
  def resize(file, size)
48
- raise InvalidGeometryError.new unless Processor.geometry_string_valid?(size)
41
+ unless Processor.geometry_string_valid?(size)
42
+ raise InvalidGeometryError.new('"%s" is not a valid ImageMagick geometry string' % size)
43
+ end
49
44
  silence_stderr do
50
45
  path = file.respond_to?(:path) ? file.path : file
51
46
  file.close if file.respond_to?(:close) && !file.closed?
@@ -105,26 +105,6 @@ module HasImage
105
105
  options[:convert_to].to_s.downcase.gsub("jpeg", "jpg")
106
106
  end
107
107
 
108
- # Returns the options[:thumbnails] hash, coverted to an array and sorted
109
- # by thumbnail area, highest to lowest. For example:
110
- #
111
- # options[:thumbnails] == {:a => "20x20", :b => "2x2", :c => "100x100"}
112
- # sorted_thumbnails == [[:c, "100x100"], [:a, "20x20"], [:b, "2x2"]]
113
- #
114
- # This is done to speed up processing images with several thumbnails. Rather
115
- # than create the thumbnail starting from the highest quality version each
116
- # time, the next biggest thumbnail is used as the base image for its
117
- # immediately smaller variant. For example, given an image with 3 thumbnails
118
- # HasImage will use the 800x800 as the basis of the 500x500, and then the
119
- # 500x500 as the basis of the 200x200, etc. My benchmarks showed that this
120
- # will speed up processing by up to around 25% for a 4.5 meg JPEG with 5
121
- # thumbnails.
122
- def sorted_thumbnails
123
- options[:thumbnails].to_a.sort do |b,a|
124
- Processor.area(a[1]) <=> Processor.area(b[1])
125
- end
126
- end
127
-
128
108
  private
129
109
 
130
110
  # File name, plus thumbnail suffix, plus extension. For example:
@@ -161,10 +141,9 @@ module HasImage
161
141
  def install_thumbnails(id, name)
162
142
  FileUtils.mkdir_p path_for(id)
163
143
  path = File.join(path_for(id), file_name_for(name))
164
- sorted_thumbnails.each do |t|
165
- thumb = processor.resize(path, t[1])
166
- path = File.join(path_for(id), file_name_for(name, t[0]))
167
- thumb.write(path)
144
+ options[:thumbnails].each do |thumb_name, size|
145
+ thumb = processor.resize(path, size)
146
+ thumb.write(File.join(path_for(id), file_name_for(name, thumb_name)))
168
147
  thumb.tempfile.close!
169
148
  end
170
149
  end
@@ -13,10 +13,6 @@ class StorageTest < Test::Unit::TestCase
13
13
  return @temp_file
14
14
  end
15
15
 
16
- def test_area
17
- assert_equal 2500, HasImage::Processor.area("50x50>")
18
- end
19
-
20
16
  def test_detect_valid_image
21
17
  assert HasImage::Processor.valid?(File.dirname(__FILE__) + "/../test_rails/fixtures/image.jpg")
22
18
  end
data/test/storage_test.rb CHANGED
@@ -16,13 +16,6 @@ class StorageTest < Test::Unit::TestCase
16
16
  )
17
17
  end
18
18
 
19
- def test_sorted_thumbnails
20
- thumbs = {:a => "20x20", :b => "2x2", :c => "100x100"}
21
- sorted = [[:c, "100x100"], [:a, "20x20"], [:b, "2x2"]]
22
- @storage = HasImage::Storage.new(default_options.merge(:thumbnails => thumbs))
23
- assert_equal sorted, @storage.send(:sorted_thumbnails)
24
- end
25
-
26
19
  def test_partitioned_path
27
20
  assert_equal(["0001", "2345"], HasImage::Storage.partitioned_path("12345"))
28
21
  end
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.1.2
4
+ version: 0.1.3
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-07-28 00:00:00 -03:00
12
+ date: 2008-07-29 00:00:00 -03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency