Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add appropriate filename extension to temp files

  • Loading branch information...
commit 4e6c214bace6957ae865c89e86da0ccba8c7f7e2 1 parent e06cc63
@sdsykes authored
View
4 README.textile
@@ -32,10 +32,10 @@ h2. Examples
=>FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
outfile = FastImage.resize("afile.png", 50, 150)
- => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-x3l8r7-0>
+ => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-x3l8r7-0.png>
File.open("afile.png", "r") {|f| FastImage.resize(f, 100, 100)}
- => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-y1ofh-0>
+ => #<File:/var/folders/vm/vd65y2597xl_by6c73_m9j1h0000gn/T/FastImage20111003-7638-y1ofh-0.png>
</code>
</pre>
View
2  VERSION.yml
@@ -1,5 +1,5 @@
---
-:patch: 1
+:patch: 2
:major: 2
:build:
:minor: 0
View
4 fastimage_resize.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{fastimage_resize}
- s.version = "2.0.1"
+ s.version = "2.0.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Stephen Sykes"]
- s.date = %q{2011-10-14}
+ s.date = %q{2011-10-15}
s.description = %q{FastImage Resize is an extremely light solution for resizing images in ruby by using libgd.}
s.email = %q{sdsykes@gmail.com}
s.extra_rdoc_files = [
View
11 lib/fastimage_resize.rb
@@ -33,6 +33,7 @@
class FastImage
SUPPORTED_FORMATS = [:jpeg, :png, :gif]
+ FILE_EXTENSIONS = [:jpg, :png, :gif] # prefer jpg to jpeg as an extension
class FormatNotSupported < FastImageException # :nodoc:
end
@@ -70,17 +71,17 @@ def self.resize(input, w, h, options={})
end
end
+ fast_image = new(file_in, :raise_on_failure=>true)
+ type_index = SUPPORTED_FORMATS.index(fast_image.type)
+ raise FormatNotSupported unless type_index
+
if !file_out
- temp_file = Tempfile.new(name)
+ temp_file = Tempfile.new([name, ".#{FILE_EXTENSIONS[type_index]}"])
file_out = temp_file.path
else
temp_file = nil
end
- fast_image = new(file_in, :raise_on_failure=>true)
- type_index = SUPPORTED_FORMATS.index(fast_image.type)
- raise FormatNotSupported unless type_index
-
in_path = file_in.respond_to?(:path) ? file_in.path : file_in
fast_image.resize_image(in_path, file_out.to_s, w.to_i, h.to_i, type_index, jpeg_quality.to_i)
View
9 test/test.rb
@@ -127,4 +127,13 @@ def test_resized_jpg_is_reasonable_size_for_quality
assert size > 1500
File.unlink outfile
end
+
+ def test_output_tempfile_has_right_extension
+ outfile = FastImage.resize(File.join(FixturePath, "test.jpg"), 200, 200)
+ assert outfile.path =~ /\.jpg$/
+ outfile = FastImage.resize(File.join(FixturePath, "test.gif"), 200, 200)
+ assert outfile.path =~ /\.gif$/
+ outfile = FastImage.resize(File.join(FixturePath, "test.png"), 200, 200)
+ assert outfile.path =~ /\.png$/
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.