image_size 1.0.5 → 1.0.6
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/.tmignore +1 -0
- data/image_size.gemspec +1 -1
- data/lib/image_size.rb +17 -20
- data/spec/image_size_spec.rb +7 -0
- metadata +5 -4
data/.tmignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/spec/test.*
|
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.
|
5
|
+
s.version = '1.0.6'
|
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}"
|
data/lib/image_size.rb
CHANGED
@@ -1,39 +1,30 @@
|
|
1
1
|
require 'stringio'
|
2
2
|
|
3
3
|
class ImageSize
|
4
|
-
JpegCodeCheck = [
|
5
|
-
"\xc0", "\xc1", "\xc2", "\xc3",
|
6
|
-
"\xc5", "\xc6", "\xc7",
|
7
|
-
"\xc9", "\xca", "\xcb",
|
8
|
-
"\xcd", "\xce", "\xcf",
|
9
|
-
]
|
10
|
-
|
11
4
|
attr_reader :format, :width, :height
|
12
5
|
|
13
6
|
# receive image & make size
|
14
7
|
# argument is image String, StringIO or IO
|
15
8
|
def initialize(data)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
img_top = @data[0, 1024]
|
26
|
-
img_io = StringIO.open(@data)
|
9
|
+
data = data.dup
|
10
|
+
|
11
|
+
case data
|
12
|
+
when IO, StringIO
|
13
|
+
img_top = data.read(1024)
|
14
|
+
img_io = def_read_o(data)
|
15
|
+
when String
|
16
|
+
img_top = data[0, 1024]
|
17
|
+
img_io = StringIO.open(data)
|
27
18
|
img_io = def_read_o(img_io)
|
28
19
|
else
|
29
|
-
raise "
|
20
|
+
raise ArgumentError.new("expected instance of IO, StringIO or String, got #{data.class}")
|
30
21
|
end
|
31
22
|
|
32
23
|
if @format = check_format(img_top)
|
33
24
|
@width, @height = self.send("measure_#{@format}", img_io)
|
34
25
|
end
|
35
26
|
|
36
|
-
if
|
27
|
+
if data.is_a?(String)
|
37
28
|
img_io.close
|
38
29
|
end
|
39
30
|
end
|
@@ -96,6 +87,12 @@ private
|
|
96
87
|
img_io.read_o(8).unpack('NN')
|
97
88
|
end
|
98
89
|
|
90
|
+
JpegCodeCheck = [
|
91
|
+
"\xc0", "\xc1", "\xc2", "\xc3",
|
92
|
+
"\xc5", "\xc6", "\xc7",
|
93
|
+
"\xc9", "\xca", "\xcb",
|
94
|
+
"\xcd", "\xce", "\xcf",
|
95
|
+
]
|
99
96
|
def measure_jpeg(img_io)
|
100
97
|
c_marker = "\xFF" # Section marker.
|
101
98
|
img_io.read_o(2)
|
data/spec/image_size_spec.rb
CHANGED
@@ -27,6 +27,13 @@ describe ImageSize do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
it "should get format and dimensions for #{name} given StringIO" do
|
31
|
+
File.open(path, 'rb') do |fh|
|
32
|
+
is = ImageSize.new(StringIO.new(fh.read))
|
33
|
+
[is.format, is.width, is.height].should == [format, width, height]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
30
37
|
it "should get format and dimensions for #{name} given file data" do
|
31
38
|
File.open(path, 'rb') do |fh|
|
32
39
|
is = ImageSize.new(fh.read)
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 6
|
10
|
+
version: 1.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Keisuke Minami
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-02-
|
19
|
+
date: 2012-02-08 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: rspec
|
@@ -42,6 +42,7 @@ extra_rdoc_files: []
|
|
42
42
|
|
43
43
|
files:
|
44
44
|
- .gitignore
|
45
|
+
- .tmignore
|
45
46
|
- README.markdown
|
46
47
|
- image_size.gemspec
|
47
48
|
- lib/image_size.rb
|