fastimage_resize 2.0.1 → 2.0.2

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/README.textile CHANGED
@@ -32,10 +32,10 @@ h2. Examples
32
32
  =>FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
33
33
 
34
34
  outfile = FastImage.resize("afile.png", 50, 150)
35
- => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-x3l8r7-0>
35
+ => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-x3l8r7-0.png>
36
36
 
37
37
  File.open("afile.png", "r") {|f| FastImage.resize(f, 100, 100)}
38
- => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-y1ofh-0>
38
+ => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-y1ofh-0.png>
39
39
  </code>
40
40
  </pre>
41
41
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 1
2
+ :patch: 2
3
3
  :major: 2
4
4
  :build:
5
5
  :minor: 0
@@ -33,6 +33,7 @@ require 'fastimage'
33
33
 
34
34
  class FastImage
35
35
  SUPPORTED_FORMATS = [:jpeg, :png, :gif]
36
+ FILE_EXTENSIONS = [:jpg, :png, :gif] # prefer jpg to jpeg as an extension
36
37
 
37
38
  class FormatNotSupported < FastImageException # :nodoc:
38
39
  end
@@ -70,17 +71,17 @@ class FastImage
70
71
  end
71
72
  end
72
73
 
74
+ fast_image = new(file_in, :raise_on_failure=>true)
75
+ type_index = SUPPORTED_FORMATS.index(fast_image.type)
76
+ raise FormatNotSupported unless type_index
77
+
73
78
  if !file_out
74
- temp_file = Tempfile.new(name)
79
+ temp_file = Tempfile.new([name, ".#{FILE_EXTENSIONS[type_index]}"])
75
80
  file_out = temp_file.path
76
81
  else
77
82
  temp_file = nil
78
83
  end
79
84
 
80
- fast_image = new(file_in, :raise_on_failure=>true)
81
- type_index = SUPPORTED_FORMATS.index(fast_image.type)
82
- raise FormatNotSupported unless type_index
83
-
84
85
  in_path = file_in.respond_to?(:path) ? file_in.path : file_in
85
86
 
86
87
  fast_image.resize_image(in_path, file_out.to_s, w.to_i, h.to_i, type_index, jpeg_quality.to_i)
data/test/test.rb CHANGED
@@ -114,4 +114,26 @@ class FastImageResizeTest < Test::Unit::TestCase
114
114
  FastImage.resize("#{TestUrl}/redirect", 20, 20)
115
115
  end
116
116
  end
117
+
118
+ def test_resized_jpg_is_reasonable_size_for_quality
119
+ outfile = File.join(PathHere, "fixtures", "resized_test.jpg")
120
+ FastImage.resize(File.join(FixturePath, "test.jpg"), 200, 200, :outfile=>outfile)
121
+ size = File.size(outfile)
122
+ assert size < 30000
123
+ assert size > 10000
124
+ FastImage.resize(File.join(FixturePath, "test.jpg"), 200, 200, :outfile=>outfile, :jpeg_quality=>5)
125
+ size = File.size(outfile)
126
+ assert size < 3500
127
+ assert size > 1500
128
+ File.unlink outfile
129
+ end
130
+
131
+ def test_output_tempfile_has_right_extension
132
+ outfile = FastImage.resize(File.join(FixturePath, "test.jpg"), 200, 200)
133
+ assert outfile.path =~ /\.jpg$/
134
+ outfile = FastImage.resize(File.join(FixturePath, "test.gif"), 200, 200)
135
+ assert outfile.path =~ /\.gif$/
136
+ outfile = FastImage.resize(File.join(FixturePath, "test.png"), 200, 200)
137
+ assert outfile.path =~ /\.png$/
138
+ end
117
139
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastimage_resize
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 1
10
- version: 2.0.1
9
+ - 2
10
+ version: 2.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Stephen Sykes
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-14 00:00:00 +03:00
18
+ date: 2011-10-15 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency