fastimage_resize 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -39,6 +39,8 @@ h2. Examples
39
39
  </code>
40
40
  </pre>
41
41
 
42
+ Giving a zero value for width or height causes the image to scale proportionately.
43
+
42
44
  h2. Installation
43
45
 
44
46
  First check the requirements section below.
@@ -44,6 +44,8 @@ class FastImage
44
44
  #
45
45
  # FastImage Resize can resize GIF, JPEG and PNG files.
46
46
  #
47
+ # Giving a zero value for width or height causes the image to scale proportionately.
48
+ #
47
49
  # === Example
48
50
  #
49
51
  # require 'fastimage_resize'
@@ -77,13 +79,14 @@ class FastImage
77
79
 
78
80
  if !file_out
79
81
  temp_file = Tempfile.new([name, ".#{FILE_EXTENSIONS[type_index]}"])
82
+ temp_file.binmode
80
83
  file_out = temp_file.path
81
84
  else
82
85
  temp_file = nil
83
86
  end
84
87
 
85
88
  in_path = file_in.respond_to?(:path) ? file_in.path : file_in
86
-
89
+
87
90
  fast_image.resize_image(in_path, file_out.to_s, w.to_i, h.to_i, type_index, jpeg_quality.to_i)
88
91
 
89
92
  if file_in.respond_to?(:close)
@@ -101,6 +104,7 @@ class FastImage
101
104
  # returns readable tempfile
102
105
  def self.read_to_local(readable)
103
106
  temp = Tempfile.new(name)
107
+ temp.binmode
104
108
  temp.write(readable.read)
105
109
  temp.close
106
110
  temp.open
@@ -122,13 +126,10 @@ class FastImage
122
126
  in = fopen(filename_in, "rb");
123
127
  if (!in) return Qnil;
124
128
 
125
- im_out = gdImageCreateTrueColor(w, h); /* must be truecolor */
126
129
  switch(image_type) {
127
130
  case 0: im_in = gdImageCreateFromJpeg(in);
128
131
  break;
129
132
  case 1: im_in = gdImageCreateFromPng(in);
130
- gdImageAlphaBlending(im_out, 0); /* handle transparency correctly */
131
- gdImageSaveAlpha(im_out, 1);
132
133
  break;
133
134
  case 2: im_in = gdImageCreateFromGif(in);
134
135
  trans = gdImageGetTransparent(im_in);
@@ -150,6 +151,23 @@ class FastImage
150
151
  break;
151
152
  default: return Qnil;
152
153
  }
154
+
155
+ if (w == 0 || h == 0) {
156
+ int originalWidth = gdImageSX(im_in);
157
+ int originalHeight = gdImageSY(im_in);
158
+ if (w == 0) {
159
+ w = (int)(h * originalWidth / originalHeight);
160
+ } else {
161
+ h = (int)(w * originalHeight / originalWidth);
162
+ }
163
+ }
164
+
165
+ im_out = gdImageCreateTrueColor(w, h); /* must be truecolor */
166
+
167
+ if (image_type == 1) {
168
+ gdImageAlphaBlending(im_out, 0); /* handle transparency correctly */
169
+ gdImageSaveAlpha(im_out, 1);
170
+ }
153
171
 
154
172
  fclose(in);
155
173
 
data/test/test.rb CHANGED
@@ -136,4 +136,26 @@ class FastImageResizeTest < Test::Unit::TestCase
136
136
  outfile = FastImage.resize(File.join(FixturePath, "test.png"), 200, 200)
137
137
  assert outfile.path =~ /\.png$/
138
138
  end
139
+
140
+ def test_zero_width_scales_proportionately
141
+ GoodFixtures.each do |fn, info|
142
+ File.open(File.join(FixturePath, fn)) do |io|
143
+ halfHeight = (info[1][1] / 2).round
144
+ outfile = FastImage.resize(io, 0, halfHeight)
145
+ newWidth = (halfHeight * info[1][0] / info[1][1]).round
146
+ assert_equal [newWidth, halfHeight], FastImage.size(outfile)
147
+ end
148
+ end
149
+ end
150
+
151
+ def test_zero_height_scales_proportionately
152
+ GoodFixtures.each do |fn, info|
153
+ File.open(File.join(FixturePath, fn)) do |io|
154
+ halfWidth = (info[1][0] / 2).round
155
+ outfile = FastImage.resize(io, halfWidth, 0)
156
+ newHeight = (halfWidth * info[1][1] / info[1][0]).round
157
+ assert_equal [halfWidth, newHeight], FastImage.size(outfile)
158
+ end
159
+ end
160
+ end
139
161
  end
metadata CHANGED
@@ -1,65 +1,57 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: fastimage_resize
3
- version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
6
- segments:
7
- - 2
8
- - 0
9
- - 2
10
- version: 2.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.3
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Stephen Sykes
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-10-15 00:00:00 +03:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: RubyInline
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 35
30
- segments:
31
- - 3
32
- - 8
33
- - 2
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 3.8.2
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: fastimage
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
41
25
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 13
46
- segments:
47
- - 1
48
- - 2
49
- - 9
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.8.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: fastimage
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
50
37
  version: 1.2.9
51
38
  type: :runtime
52
- version_requirements: *id002
53
- description: FastImage Resize is an extremely light solution for resizing images in ruby by using libgd.
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.9
46
+ description: FastImage Resize is an extremely light solution for resizing images in
47
+ ruby by using libgd.
54
48
  email: sdsykes@gmail.com
55
49
  executables: []
56
-
57
50
  extensions: []
58
-
59
- extra_rdoc_files:
51
+ extra_rdoc_files:
60
52
  - README
61
53
  - README.textile
62
- files:
54
+ files:
63
55
  - README
64
56
  - README.textile
65
57
  - Rakefile
@@ -72,39 +64,31 @@ files:
72
64
  - test/fixtures/test.jpg
73
65
  - test/fixtures/test.png
74
66
  - test/test.rb
75
- has_rdoc: true
76
67
  homepage: http://github.com/sdsykes/fastimage_resize
77
68
  licenses: []
78
-
79
69
  post_install_message:
80
- rdoc_options:
70
+ rdoc_options:
81
71
  - --charset=UTF-8
82
- require_paths:
72
+ require_paths:
83
73
  - lib
84
- required_ruby_version: !ruby/object:Gem::Requirement
74
+ required_ruby_version: !ruby/object:Gem::Requirement
85
75
  none: false
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- hash: 3
90
- segments:
91
- - 0
92
- version: "0"
93
- required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
81
  none: false
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- hash: 3
99
- segments:
100
- - 0
101
- version: "0"
102
- requirements:
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements:
103
87
  - libgd, see www.libgd.org
104
88
  rubyforge_project:
105
- rubygems_version: 1.3.7
89
+ rubygems_version: 1.8.23
106
90
  signing_key:
107
91
  specification_version: 3
108
92
  summary: FastImage Resize - Image resizing fast and simple
109
- test_files:
93
+ test_files:
110
94
  - test/test.rb