image_size 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/image_size.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'image_size'
5
- s.version = '1.0.4'
5
+ s.version = '1.0.5'
6
6
  s.summary = %q{Measure image size using pure Ruby}
7
7
  s.description = %q{Measure following file dimensions: PCX, PSD, XPM, TIFF, XBM, PGM, PBM, PPM, BMP, JPEG, PNG, GIF, SWF}
8
8
  s.homepage = "http://github.com/toy/#{s.name}"
@@ -15,4 +15,6 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = %w[lib]
18
+
19
+ s.add_development_dependency 'rspec'
18
20
  end
data/lib/image_size.rb CHANGED
@@ -14,9 +14,6 @@ class ImageSize
14
14
  # argument is image String, StringIO or IO
15
15
  def initialize(data)
16
16
  @data = data.dup
17
- @width = nil
18
- @height = nil
19
- @format = nil
20
17
 
21
18
  if @data.is_a?(IO)
22
19
  img_top = @data.read(1024)
@@ -83,8 +80,8 @@ private
83
80
  when img_top[0, 4] == "II\x2a\x00" then :tiff
84
81
  when img_top =~ /\/\* XPM \*\// then :xpm
85
82
  when img_top[0, 4] == '8BPS' then :psd
86
- when img_top[1, 2] == 'WS' then :swf
87
- when img_top[0] == 10 then :pcx
83
+ when img_top =~ /^[FC]WS/ then :swf
84
+ when img_top[0, 1] == "\x0a" then :pcx
88
85
  end
89
86
  end
90
87
 
@@ -212,11 +209,7 @@ private
212
209
  sig2 = header[1, 1]
213
210
  sig3 = header[2, 1]
214
211
 
215
- unless ((sig1 == 'F' || sig1 == 'C') && sig2 == 'W' && sig3 == 'S')
216
- raise 'This file is not SWF.'
217
- end
218
-
219
- bit_length = Integer("0b#{header.unpack('@8B5')}")
212
+ bit_length = Integer("0b#{header.unpack('@8B5').first}")
220
213
  header << img_io.read_o(bit_length * 4 / 8 + 1)
221
214
  str = header.unpack("@8B#{5 + bit_length * 4}")[0]
222
215
  last = 5
@@ -0,0 +1,37 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'rspec'
3
+ require 'image_size'
4
+
5
+ describe ImageSize do
6
+ [
7
+ ['test.bmp', :bmp, 50, 50],
8
+ ['test.gif', :gif, 668, 481],
9
+ ['test.jpg', :jpeg, 320, 240],
10
+ ['test.pbm', :pbm, 85, 55],
11
+ ['test.pcx', :pcx, 70, 60],
12
+ ['test.pgm', :pgm, 90, 55],
13
+ ['test.png', :png, 640, 532],
14
+ ['test.psd', :psd, 20, 20],
15
+ ['test.swf', :swf, 450, 200],
16
+ ['test.tif', :tiff, 64, 64],
17
+ ['test.xbm', :xbm, 16, 16],
18
+ ['test.xpm', :xpm, 32, 32],
19
+ ['image_size_spec.rb', nil, nil, nil],
20
+ ].each do |name, format, width, height|
21
+ path = File.join(File.dirname(__FILE__), name)
22
+
23
+ it "should get format and dimensions for #{name} given io" do
24
+ File.open(path, 'rb') do |fh|
25
+ is = ImageSize.new(fh)
26
+ [is.format, is.width, is.height].should == [format, width, height]
27
+ end
28
+ end
29
+
30
+ it "should get format and dimensions for #{name} given file data" do
31
+ File.open(path, 'rb') do |fh|
32
+ is = ImageSize.new(fh.read)
33
+ [is.format, is.width, is.height].should == [format, width, height]
34
+ end
35
+ end
36
+ end
37
+ end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: image_size
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 4
10
- version: 1.0.4
9
+ - 5
10
+ version: 1.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Keisuke Minami
@@ -16,9 +16,22 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-12-16 00:00:00 Z
20
- dependencies: []
21
-
19
+ date: 2012-02-04 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
22
35
  description: "Measure following file dimensions: PCX, PSD, XPM, TIFF, XBM, PGM, PBM, PPM, BMP, JPEG, PNG, GIF, SWF"
23
36
  email:
24
37
  executables: []
@@ -32,20 +45,19 @@ files:
32
45
  - README.markdown
33
46
  - image_size.gemspec
34
47
  - lib/image_size.rb
35
- - test/2-4-7.png
36
- - test/4_1_2.gif
37
- - test/bmp.bmp
38
- - test/cursor.xbm
39
- - test/detect.swf
40
- - test/pbm.pbm
41
- - test/pcx.pcx
42
- - test/pgm.pgm
43
- - test/test.xpm
44
- - test/test_helper.rb
45
- - test/test_image_size.rb
46
- - test/tiff.tiff
47
- - test/tokyo_tower.jpg
48
- - test/tower_e.psd
48
+ - spec/image_size_spec.rb
49
+ - spec/test.bmp
50
+ - spec/test.gif
51
+ - spec/test.jpg
52
+ - spec/test.pbm
53
+ - spec/test.pcx
54
+ - spec/test.pgm
55
+ - spec/test.png
56
+ - spec/test.psd
57
+ - spec/test.swf
58
+ - spec/test.tif
59
+ - spec/test.xbm
60
+ - spec/test.xpm
49
61
  homepage: http://github.com/toy/image_size
50
62
  licenses:
51
63
  - MIT
@@ -75,23 +87,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
87
  requirements: []
76
88
 
77
89
  rubyforge_project: image_size
78
- rubygems_version: 1.8.12
90
+ rubygems_version: 1.8.15
79
91
  signing_key:
80
92
  specification_version: 3
81
93
  summary: Measure image size using pure Ruby
82
94
  test_files:
83
- - test/2-4-7.png
84
- - test/4_1_2.gif
85
- - test/bmp.bmp
86
- - test/cursor.xbm
87
- - test/detect.swf
88
- - test/pbm.pbm
89
- - test/pcx.pcx
90
- - test/pgm.pgm
91
- - test/test.xpm
92
- - test/test_helper.rb
93
- - test/test_image_size.rb
94
- - test/tiff.tiff
95
- - test/tokyo_tower.jpg
96
- - test/tower_e.psd
95
+ - spec/image_size_spec.rb
96
+ - spec/test.bmp
97
+ - spec/test.gif
98
+ - spec/test.jpg
99
+ - spec/test.pbm
100
+ - spec/test.pcx
101
+ - spec/test.pgm
102
+ - spec/test.png
103
+ - spec/test.psd
104
+ - spec/test.swf
105
+ - spec/test.tif
106
+ - spec/test.xbm
107
+ - spec/test.xpm
97
108
  has_rdoc:
data/test/test_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- require 'test/unit'
2
- require File.dirname(__FILE__) + '/../lib/image_size'
@@ -1,50 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
2
-
3
- class TestImageSize < Test::Unit::TestCase
4
-
5
- def setup
6
- @dir = File.dirname(__FILE__)
7
- @data = [
8
- ['4_1_2.gif', :gif, 668, 481],
9
- ['2-4-7.png', :png, 640, 532],
10
- ['tokyo_tower.jpg', :jpeg, 320, 240],
11
- ['bmp.bmp', :bmp, 50, 50],
12
- ['pgm.pgm', :pgm, 90, 55],
13
- ['pbm.pbm', :pbm, 85, 55],
14
- ['cursor.xbm', :xbm, 16, 16],
15
- ['tiff.tiff', :tiff, 64, 64],
16
- ['test.xpm', :xpm, 32, 32],
17
- ['tower_e.psd', :psd, 20, 20],
18
- ['pcx.pcx', :pcx, 70, 60],
19
- ['detect.swf', :swf, 450, 200],
20
- ['test_helper.rb', nil, nil, nil],
21
- ]
22
- end
23
-
24
- def teardown
25
- end
26
-
27
- def test_string
28
- @data.each do |file_name, format, widht, height|
29
- open(File.join(@dir, file_name), 'rb') do |fh|
30
- img_data = fh.read
31
-
32
- img = ImageSize.new(img_data)
33
- assert_equal(format, img.format)
34
- assert_equal(widht, img.width)
35
- assert_equal(height, img.height)
36
- end
37
- end
38
- end
39
-
40
- def test_io
41
- @data.each do |file_name, format, widht, height|
42
- open(File.join(@dir, file_name), 'rb') do |fh|
43
- img = ImageSize.new(fh)
44
- assert_equal(format, img.format)
45
- assert_equal(widht, img.width)
46
- assert_equal(height, img.height)
47
- end
48
- end
49
- end
50
- end