├── MIT_LICENCE ├── README ├── README.textile ├── Rakefile ├── VERSION.yml ├── fastimage_resize.gemspec ├── lib └── fastimage_resize.rb └── test ├── fixtures ├── faulty.jpg ├── test with space.jpg ├── test.bmp ├── test.gif ├── test.ico ├── test.jpg └── test.png └── test.rb /MIT_LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2011 Stephen Sykes 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | FastImage Resize is an extremely light solution for resizing images in ruby by using libgd 2 | 3 | === Examples 4 | 5 | require 'fastimage_resize' 6 | 7 | FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", "my.gif", 100, 20) 8 | => 1 9 | 10 | === Requirements 11 | 12 | RubyInline 13 | 14 | gem install RubyInline 15 | 16 | FastImage 17 | 18 | gem install fastimage 19 | 20 | Libgd 21 | 22 | See http://www.libgd.org/ 23 | Libgd is commonly available on most unix platforms, including OSX. 24 | 25 | === References 26 | 27 | * http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing 28 | -------------------------------------------------------------------------------- /README.textile: -------------------------------------------------------------------------------- 1 | h1. FastImage Resize 2 | 3 | h2. Not maintained since 2015. Let me know if you'd like to help out. 4 | 5 | h4. FastImage Resize is an extremely light solution for resizing images in ruby by using libgd 6 | 7 | FastImage Resize will resize gifs, jpegs, and png files. 8 | 9 | It uses resampling to get good looking results. 10 | 11 | And it doesn't rely on installing external heavy libraries such as RMagick (which relies on ImageMagick or GraphicsMagick) or ImageScience (which relies on FreeImage). 12 | 13 | FastImage Resize uses *Libgd*, which is commonly available on most unix platforms, including OSX. It is very likely that you already have this software installed on your server. 14 | 15 | As its input, FastImage Resize can take a URI, a filename, or an IO object (or anything that responds to :read). 16 | If you do not supply an output filename in the :outfile option, FastImage Resize will return you a Tempfile object. This will be unlinked when it is finalized during garbage collection. 17 | 18 | FastImage Resize relies on "RubyInline":https://github.com/seattlerb/rubyinline for compiling and managing the C extension code. 19 | 20 | h4. Incompatible API change Version 2.0.0 and above 21 | 22 | Note that the parameters for version 2.0.0 have changed, the output filename is no longer the second parameter. See the examples. 23 | 24 | h2. Examples 25 | 26 |
 27 | 
 28 |   require 'fastimage_resize'
 29 | 
 30 |   FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", 100, 20, :outfile=>"my.gif")
 31 |   => nil
 32 | 
 33 |   outfile = FastImage.resize("nonexistentfile.png", 50, 50)
 34 |   =>FastImage::ImageFetchFailure: FastImage::ImageFetchFailure
 35 | 
 36 |   outfile = FastImage.resize("afile.png", 50, 150)
 37 |   => #
 38 |   
 39 |   File.open("afile.png", "r") {|f| FastImage.resize(f, 100, 100)}
 40 |   => #
 41 | 
 42 | 
43 | 44 | Giving a zero value for width or height causes the image to scale proportionately. 45 | 46 | h2. Installation 47 | 48 | First check the requirements section below. 49 | 50 | h4. Gem 51 | 52 |
 53 | 
 54 |   gem install fastimage_resize
 55 | 
56 | 57 | 58 | h4. Rails 59 | 60 | Install the gem as above, and for Rails 2 configure it in your environment.rb file as below: 61 |
 62 | 
 63 | ...
 64 | Rails::Initializer.run do |config|
 65 |   ...
 66 |   config.gem "fastimage_resize"
 67 |   ...
 68 | end
 69 | ...
 70 | 
 71 | 
72 | 73 | For Rails 3, add this to your Gemfile: 74 | 75 |
 76 | 
 77 | gem 'fastimage_resize'
 78 | 
 79 | 
80 | 81 | For any Rails version, you may also need this in your environment.rb so that the rails process puts the compiled C code in a place it can access: 82 | 83 |
 84 | 
 85 | ENV['INLINEDIR'] = RAILS_ROOT + "/tmp"  # for RubyInline
 86 | 
 87 | 
88 | 89 | Then you're off - just use FastImage.resize() in your code as in the examples. 90 | 91 | h2. Requirements 92 | 93 | * RubyInline 94 | 95 |
 96 | 
 97 |   gem install RubyInline
 98 | 
99 | 100 | 101 | * FastImage 102 | 103 |
104 | 
105 |   gem install fastimage
106 | 
107 | 108 | 109 | * Libgd 110 | 111 | See "http://www.libgd.org/":http://www.libgd.org/ 112 | 113 | Libgd is commonly available on most unix platforms, including OSX. 114 | 115 | On OSX, if you have "macports":http://www.macports.org/ you can use. 116 | 117 |
118 | 
119 |   sudo port install gd2
120 | 
121 | 
122 | 123 | It is also available in "homebrew":http://github.com/mxcl/homebrew (search for gd), and "fink":http://www.finkproject.org/ (try fink install gd2 gd2-bin). 124 | 125 | h2. Documentation 126 | 127 | "http://rdoc.info/projects/sdsykes/fastimage_resize":http://rdoc.info/projects/sdsykes/fastimage_resize 128 | 129 | h2. Caveats 130 | 131 | Because of the way that libgd works, gif files that have transparency may not always come through with the transparency perfectly retained. 132 | 133 | 134 | h2. Tests 135 | 136 | You'll need to 'gem install fakeweb' to be able to run the tests 137 | 138 | h2. References 139 | 140 | * "http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing":http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing 141 | 142 | h2. Licence 143 | 144 | MIT, see file MIT_LICENCE 145 | 146 | h2. Author 147 | 148 | Stephen Sykes, @sdsykes 149 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake' 2 | 3 | begin 4 | require 'jeweler' 5 | Jeweler::Tasks.new do |s| 6 | s.name = "fastimage_resize" 7 | s.summary = "FastImage Resize - Image resizing fast and simple" 8 | s.email = "sdsykes@gmail.com" 9 | s.homepage = "http://github.com/sdsykes/fastimage_resize" 10 | s.description = "FastImage Resize is an extremely light solution for resizing images in ruby by using libgd." 11 | s.authors = ["Stephen Sykes"] 12 | s.files = FileList["[A-Z]*", "{lib,test}/**/*"] 13 | s.requirements << 'libgd, see www.libgd.org' 14 | s.add_dependency('RubyInline', '>= 3.8.2') 15 | s.add_dependency('fastimage', '>= 1.2.0') 16 | end 17 | Jeweler::GemcutterTasks.new 18 | rescue LoadError 19 | puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http:// 20 | gems.github.com" 21 | end 22 | -------------------------------------------------------------------------------- /VERSION.yml: -------------------------------------------------------------------------------- 1 | --- 2 | :patch: 2 3 | :major: 2 4 | :build: 5 | :minor: 0 6 | -------------------------------------------------------------------------------- /fastimage_resize.gemspec: -------------------------------------------------------------------------------- 1 | # Generated by jeweler 2 | # DO NOT EDIT THIS FILE DIRECTLY 3 | # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command 4 | # -*- encoding: utf-8 -*- 5 | 6 | Gem::Specification.new do |s| 7 | s.name = %q{fastimage_resize} 8 | s.version = "2.0.3" 9 | 10 | s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= 11 | s.authors = ["Stephen Sykes"] 12 | s.date = %q{2012-05-12} 13 | s.description = %q{FastImage Resize is an extremely light solution for resizing images in ruby by using libgd.} 14 | s.email = %q{sdsykes@gmail.com} 15 | s.extra_rdoc_files = [ 16 | "README", 17 | "README.textile" 18 | ] 19 | s.files = [ 20 | "README", 21 | "README.textile", 22 | "Rakefile", 23 | "VERSION.yml", 24 | "lib/fastimage_resize.rb", 25 | "test/fixtures/faulty.jpg", 26 | "test/fixtures/test.bmp", 27 | "test/fixtures/test.gif", 28 | "test/fixtures/test.ico", 29 | "test/fixtures/test.jpg", 30 | "test/fixtures/test.png", 31 | "test/test.rb" 32 | ] 33 | s.homepage = %q{http://github.com/sdsykes/fastimage_resize} 34 | s.rdoc_options = ["--charset=UTF-8"] 35 | s.require_paths = ["lib"] 36 | s.requirements = ["libgd, see www.libgd.org"] 37 | s.rubygems_version = %q{1.3.6} 38 | s.summary = %q{FastImage Resize - Image resizing fast and simple} 39 | s.test_files = [ 40 | "test/test.rb" 41 | ] 42 | 43 | if s.respond_to? :specification_version then 44 | current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION 45 | s.specification_version = 3 46 | 47 | if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then 48 | s.add_runtime_dependency(%q, [">= 3.8.2"]) 49 | s.add_runtime_dependency(%q, [">= 1.2.9"]) 50 | else 51 | s.add_dependency(%q, [">= 3.8.2"]) 52 | s.add_dependency(%q, [">= 1.2.9"]) 53 | end 54 | else 55 | s.add_dependency(%q, [">= 3.8.2"]) 56 | s.add_dependency(%q, [">= 1.2.9"]) 57 | end 58 | end 59 | 60 | -------------------------------------------------------------------------------- /lib/fastimage_resize.rb: -------------------------------------------------------------------------------- 1 | # FastImage Resize is an extremely light solution for resizing images in ruby by using libgd 2 | # 3 | # === Examples 4 | # 5 | # require 'fastimage_resize' 6 | # 7 | # FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", 100, 20, :outfile=>"my.gif") 8 | # => 1 9 | # 10 | # === Requirements 11 | # 12 | # RubyInline 13 | # 14 | # gem install RubyInline 15 | # 16 | # FastImage 17 | # 18 | # gem install fastimage 19 | # 20 | # Libgd 21 | # 22 | # See http://www.libgd.org/ 23 | # Libgd is commonly available on most unix platforms, including OSX. 24 | # 25 | # === References 26 | # 27 | # * http://blog.new-bamboo.co.uk/2007/12/3/super-f-simple-resizing 28 | 29 | require 'inline' 30 | require 'open-uri' 31 | require 'tempfile' 32 | require 'fastimage' 33 | 34 | class FastImage 35 | SUPPORTED_FORMATS = [:jpeg, :png, :gif] 36 | FILE_EXTENSIONS = [:jpg, :png, :gif] # prefer jpg to jpeg as an extension 37 | 38 | class FormatNotSupported < FastImageException # :nodoc: 39 | end 40 | 41 | # Resizes an image, storing the result in a file given in file_out 42 | # 43 | # Input can be a filename, a uri, or an IO object. 44 | # 45 | # FastImage Resize can resize GIF, JPEG and PNG files. 46 | # 47 | # Giving a zero value for width or height causes the image to scale proportionately. 48 | # 49 | # === Example 50 | # 51 | # require 'fastimage_resize' 52 | # 53 | # FastImage.resize("http://stephensykes.com/images/ss.com_x.gif", 100, 20, :outfile=>"my.gif") 54 | # 55 | # === Supported options 56 | # [:jpeg_quality] 57 | # A figure passed to libgd to determine quality of output jpeg (only useful if input is jpeg) 58 | # [:outfile] 59 | # Name of a file to store the output in, in this case a temp file is not used 60 | # 61 | def self.resize(input, w, h, options={}) 62 | jpeg_quality = options[:jpeg_quality] || -1 63 | file_out = options[:outfile] 64 | 65 | if input.respond_to?(:read) 66 | file_in = read_to_local(input) 67 | else 68 | if input =~ URI.regexp(['http','https','ftp']) 69 | u = URI.parse(input) 70 | file_in = read_to_local(open(u)) 71 | else 72 | file_in = input.to_s 73 | end 74 | end 75 | 76 | fast_image = new(file_in, :raise_on_failure=>true) 77 | type_index = SUPPORTED_FORMATS.index(fast_image.type) 78 | raise FormatNotSupported unless type_index 79 | 80 | if !file_out 81 | temp_file = Tempfile.new([name, ".#{FILE_EXTENSIONS[type_index]}"]) 82 | temp_file.binmode 83 | file_out = temp_file.path 84 | else 85 | temp_file = nil 86 | end 87 | 88 | in_path = file_in.respond_to?(:path) ? file_in.path : file_in 89 | 90 | fast_image.resize_image(in_path, file_out.to_s, w.to_i, h.to_i, type_index, jpeg_quality.to_i) 91 | 92 | if file_in.respond_to?(:close) 93 | file_in.close 94 | file_in.unlink 95 | end 96 | 97 | temp_file 98 | rescue OpenURI::HTTPError, SocketError, URI::InvalidURIError, RuntimeError => e 99 | raise ImageFetchFailure, e.class 100 | end 101 | 102 | private 103 | 104 | # returns readable tempfile 105 | def self.read_to_local(readable) 106 | temp = Tempfile.new(name) 107 | temp.binmode 108 | temp.write(readable.read) 109 | temp.close 110 | temp.open 111 | temp 112 | end 113 | 114 | def resize_image(filename_in, filename_out, w, h, image_type, jpeg_quality); end 115 | 116 | inline do |builder| 117 | builder.include '"gd.h"' 118 | builder.add_link_flags "-lgd" 119 | 120 | builder.c <<-"END" 121 | VALUE resize_image(char *filename_in, char *filename_out, int w, int h, int image_type, int jpeg_quality) { 122 | gdImagePtr im_in, im_out; 123 | FILE *in, *out; 124 | int trans = 0, x = 0, y = 0, f = 0; 125 | 126 | in = fopen(filename_in, "rb"); 127 | if (!in) return Qnil; 128 | 129 | switch(image_type) { 130 | case 0: im_in = gdImageCreateFromJpeg(in); 131 | break; 132 | case 1: im_in = gdImageCreateFromPng(in); 133 | break; 134 | case 2: im_in = gdImageCreateFromGif(in); 135 | trans = gdImageGetTransparent(im_in); 136 | /* find a transparent pixel, then turn off transparency 137 | so that it copies correctly */ 138 | if (trans >= 0) { 139 | for (x=0; x= 0) { 188 | trans = gdImageGetPixel(im_out, x, y); /* get the color index of our transparent pixel */ 189 | gdImageColorTransparent(im_out, trans); /* may not always work as hoped */ 190 | } 191 | gdImageGif(im_out, out); 192 | break; 193 | } 194 | fclose(out); 195 | } 196 | gdImageDestroy(im_in); 197 | gdImageDestroy(im_out); 198 | return Qnil; 199 | } 200 | END 201 | end 202 | end 203 | -------------------------------------------------------------------------------- /test/fixtures/faulty.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdsykes/fastimage_resize/d3dd148ec9b2b6441379ca9620c5a5e8cdbd75d5/test/fixtures/faulty.jpg -------------------------------------------------------------------------------- /test/fixtures/test with space.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdsykes/fastimage_resize/d3dd148ec9b2b6441379ca9620c5a5e8cdbd75d5/test/fixtures/test with space.jpg -------------------------------------------------------------------------------- /test/fixtures/test.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdsykes/fastimage_resize/d3dd148ec9b2b6441379ca9620c5a5e8cdbd75d5/test/fixtures/test.bmp -------------------------------------------------------------------------------- /test/fixtures/test.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdsykes/fastimage_resize/d3dd148ec9b2b6441379ca9620c5a5e8cdbd75d5/test/fixtures/test.gif -------------------------------------------------------------------------------- /test/fixtures/test.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdsykes/fastimage_resize/d3dd148ec9b2b6441379ca9620c5a5e8cdbd75d5/test/fixtures/test.ico -------------------------------------------------------------------------------- /test/fixtures/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdsykes/fastimage_resize/d3dd148ec9b2b6441379ca9620c5a5e8cdbd75d5/test/fixtures/test.jpg -------------------------------------------------------------------------------- /test/fixtures/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sdsykes/fastimage_resize/d3dd148ec9b2b6441379ca9620c5a5e8cdbd75d5/test/fixtures/test.png -------------------------------------------------------------------------------- /test/test.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | 3 | require 'test/unit' 4 | 5 | PathHere = File.dirname(__FILE__) 6 | 7 | require File.join(".", PathHere, "..", "lib", 'fastimage_resize') 8 | 9 | require 'fakeweb' 10 | 11 | FixturePath = File.join(PathHere, "fixtures") 12 | 13 | GoodFixtures = { 14 | "test.gif"=>[:gif, [17, 32]], 15 | "test.jpg"=>[:jpeg, [882, 470]], 16 | "test.png"=>[:png, [30, 20]] 17 | } 18 | 19 | BadFixtures = [ 20 | "test.bmp", 21 | "faulty.jpg", 22 | "test.ico" 23 | ] 24 | 25 | TestUrl = "http://www.example.nowhere/" 26 | 27 | GoodFixtures.each do |fn, info| 28 | FakeWeb.register_uri(:get, "#{TestUrl}#{fn}", :body => File.join(FixturePath, fn)) 29 | end 30 | BadFixtures.each do |fn| 31 | FakeWeb.register_uri(:get, "#{TestUrl}#{fn}", :body => File.join(FixturePath, fn)) 32 | end 33 | 34 | redirect_response = <redirect_response) 42 | 43 | class FastImageResizeTest < Test::Unit::TestCase 44 | def test_resize_image_types_from_http 45 | GoodFixtures.each do |fn, info| 46 | outfile = File.join(PathHere, "fixtures", "resized_" + fn) 47 | FastImage.resize(TestUrl + fn, info[1][0] / 3, info[1][1] / 2, :outfile=>outfile) 48 | assert_equal [info[1][0] / 3, info[1][1] / 2], FastImage.size(outfile) 49 | File.unlink outfile 50 | end 51 | end 52 | 53 | def test_resize_image_types_from_files 54 | GoodFixtures.each do |fn, info| 55 | outfile = File.join(PathHere, "fixtures", "resized_" + fn) 56 | FastImage.resize(File.join(FixturePath, fn), info[1][0] / 3, info[1][1] / 2, :outfile=>outfile) 57 | assert_equal [info[1][0] / 3, info[1][1] / 2], FastImage.size(outfile) 58 | File.unlink outfile 59 | end 60 | end 61 | 62 | def test_resize_image_types_from_io_objects 63 | GoodFixtures.each do |fn, info| 64 | outfile = File.join(PathHere, "fixtures", "resized_" + fn) 65 | File.open(File.join(FixturePath, fn)) do |io| 66 | FastImage.resize(io, info[1][0] / 3, info[1][1] / 2, :outfile=>outfile) 67 | assert_equal [info[1][0] / 3, info[1][1] / 2], FastImage.size(outfile) 68 | File.unlink outfile 69 | end 70 | end 71 | end 72 | 73 | def test_resize_to_temp_file 74 | GoodFixtures.each do |fn, info| 75 | File.open(File.join(FixturePath, fn)) do |io| 76 | outfile = FastImage.resize(io, info[1][0] / 3, info[1][1] / 2) 77 | assert_equal [info[1][0] / 3, info[1][1] / 2], FastImage.size(outfile) 78 | end 79 | end 80 | end 81 | 82 | def test_should_raise_for_bmp_files 83 | fn = BadFixtures[0] 84 | outfile = File.join(PathHere, "fixtures", "resized_" + fn) 85 | assert_raises(FastImage::FormatNotSupported) do 86 | FastImage.resize(TestUrl + fn, 20, 20, :outfile=>outfile) 87 | end 88 | end 89 | 90 | def test_should_raise_for_faulty_files 91 | fn = BadFixtures[1] 92 | outfile = File.join(PathHere, "fixtures", "resized_" + fn) 93 | assert_raises(FastImage::SizeNotFound) do 94 | FastImage.resize(TestUrl + fn, 20, 20, :outfile=>outfile) 95 | end 96 | end 97 | 98 | def test_should_raise_for_ico_files 99 | fn = BadFixtures[2] 100 | outfile = File.join(PathHere, "fixtures", "resized_" + fn) 101 | assert_raises(FastImage::FormatNotSupported) do 102 | FastImage.resize(TestUrl + fn, 20, 20, :outfile=>outfile) 103 | end 104 | end 105 | 106 | def test_should_raise_for_invalid_uri 107 | assert_raises(FastImage::ImageFetchFailure) do 108 | FastImage.resize("#{TestUrl}////%&redirect", 20, 20) 109 | end 110 | end 111 | 112 | def test_should_raise_for_redirect 113 | assert_raises(FastImage::ImageFetchFailure) do 114 | FastImage.resize("#{TestUrl}/redirect", 20, 20) 115 | end 116 | end 117 | 118 | def test_should_resize_names_with_spaces 119 | outfile = File.join(PathHere, "fixtures", "resized_test with space.jpg") 120 | FastImage.resize(File.join(FixturePath, "test with space.jpg"), 10, 10, :outfile=>outfile) 121 | assert File.exists?(outfile) 122 | File.unlink outfile 123 | end 124 | 125 | def test_resized_jpg_is_reasonable_size_for_quality 126 | outfile = File.join(PathHere, "fixtures", "resized_test.jpg") 127 | FastImage.resize(File.join(FixturePath, "test.jpg"), 200, 200, :outfile=>outfile) 128 | size = File.size(outfile) 129 | assert size < 30000 130 | assert size > 10000 131 | FastImage.resize(File.join(FixturePath, "test.jpg"), 200, 200, :outfile=>outfile, :jpeg_quality=>5) 132 | size = File.size(outfile) 133 | assert size < 3500 134 | assert size > 1500 135 | File.unlink outfile 136 | end 137 | 138 | def test_output_tempfile_has_right_extension 139 | outfile = FastImage.resize(File.join(FixturePath, "test.jpg"), 200, 200) 140 | assert outfile.path =~ /\.jpg$/ 141 | outfile = FastImage.resize(File.join(FixturePath, "test.gif"), 200, 200) 142 | assert outfile.path =~ /\.gif$/ 143 | outfile = FastImage.resize(File.join(FixturePath, "test.png"), 200, 200) 144 | assert outfile.path =~ /\.png$/ 145 | end 146 | 147 | def test_zero_width_scales_proportionately 148 | GoodFixtures.each do |fn, info| 149 | File.open(File.join(FixturePath, fn)) do |io| 150 | halfHeight = (info[1][1] / 2).round 151 | outfile = FastImage.resize(io, 0, halfHeight) 152 | newWidth = (halfHeight * info[1][0] / info[1][1]).round 153 | assert_equal [newWidth, halfHeight], FastImage.size(outfile) 154 | end 155 | end 156 | end 157 | 158 | def test_zero_height_scales_proportionately 159 | GoodFixtures.each do |fn, info| 160 | File.open(File.join(FixturePath, fn)) do |io| 161 | halfWidth = (info[1][0] / 2).round 162 | outfile = FastImage.resize(io, halfWidth, 0) 163 | newHeight = (halfWidth * info[1][1] / info[1][0]).round 164 | assert_equal [halfWidth, newHeight], FastImage.size(outfile) 165 | end 166 | end 167 | end 168 | end 169 | --------------------------------------------------------------------------------