image_size 1.2.0 → 1.3.0
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.
- checksums.yaml +8 -8
- data/image_size.gemspec +1 -1
- data/lib/image_size.rb +6 -4
- data/spec/image_size_spec.rb +11 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmNlNjk3NjQ1N2ZjYzFiOTc5MjU5N2ZhY2JlNjI4M2ZlNTUwNTA0Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODQ2MTBiYTg4ZjA1ZTZjZDVjM2ZiNzc1NWQ5ODYxZTgyNmUwNjM4OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDA3NTQ4YzdkMTRjZmRiNGIxZTdkN2QxNTI5N2I3YzBkZWI5NjU3ODQ3ZmQz
|
10
|
+
Y2M4NDkxMTgxODQ1MGI4MzhlZWI0NjE0MmY2NTQyN2ZkNjgzMzUxNTIwYTYw
|
11
|
+
YWU1MThhYWYzZmUzMTMxZGMxOTFmY2FmMTQzNmQ0YTI3MzRmZjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGViZWJmNTY3ZTA1ZWJkNjcyMjE5YjQ0ZTViMTkxNzA4NmY3ZmU2MjkyNzJj
|
14
|
+
MjM0YzUyNjkyODRhZWY1YmY1MTBjOWVmZWZmNDgzMGZlMjg4OTg0ZDY0NTUx
|
15
|
+
ZDM3MzZkMWFjMTE1N2YwMGFjMWNmNDY0ZGRjYWJiMDg2NDFkZTY=
|
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.
|
5
|
+
s.version = '1.3.0'
|
6
6
|
s.summary = %q{Measure image size using pure Ruby}
|
7
7
|
s.description = %q{Measure following file dimensions: bmp, gif, jpeg, pbm, pcx, pgm, png, ppm, psd, swf, tiff, xbm, xpm}
|
8
8
|
s.homepage = "http://github.com/toy/#{s.name}"
|
data/lib/image_size.rb
CHANGED
@@ -4,6 +4,8 @@ require 'stringio'
|
|
4
4
|
require 'tempfile'
|
5
5
|
|
6
6
|
class ImageSize
|
7
|
+
class FormatError < StandardError; end
|
8
|
+
|
7
9
|
class Size < Array
|
8
10
|
# join using 'x'
|
9
11
|
def to_s
|
@@ -118,7 +120,7 @@ private
|
|
118
120
|
|
119
121
|
def size_of_png(ir)
|
120
122
|
unless ir[12, 4] == 'IHDR'
|
121
|
-
raise 'IHDR not in place for PNG'
|
123
|
+
raise FormatError, 'IHDR not in place for PNG'
|
122
124
|
end
|
123
125
|
ir[16, 8].unpack('NN')
|
124
126
|
end
|
@@ -135,7 +137,7 @@ private
|
|
135
137
|
loop do
|
136
138
|
marker, code, length = ir[offset, 4].unpack('aan')
|
137
139
|
offset += 4
|
138
|
-
raise 'JPEG marker not found' if marker != section_marker
|
140
|
+
raise FormatError, 'JPEG marker not found' if marker != section_marker
|
139
141
|
|
140
142
|
if JpegCodeCheck.include?(code)
|
141
143
|
return ir[offset + 1, 4].unpack('nn').reverse
|
@@ -179,7 +181,7 @@ private
|
|
179
181
|
length = 1024
|
180
182
|
until (data = ir[0, length]) =~ /"\s*(\d+)\s+(\d+)(\s+\d+\s+\d+){1,2}\s*"/m
|
181
183
|
if data.length != length
|
182
|
-
raise 'XPM size not found'
|
184
|
+
raise FormatError, 'XPM size not found'
|
183
185
|
end
|
184
186
|
length += 1024
|
185
187
|
end
|
@@ -203,7 +205,7 @@ private
|
|
203
205
|
width = height = nil
|
204
206
|
until width && height
|
205
207
|
ifd = ir[offset, 12]
|
206
|
-
raise 'Reached end of directory entries in TIFF' if ifd.nil? || offset > num_dirent
|
208
|
+
raise FormatError, 'Reached end of directory entries in TIFF' if ifd.nil? || offset > num_dirent
|
207
209
|
tag, type = ifd.unpack(endian2b * 2)
|
208
210
|
offset += 12
|
209
211
|
|
data/spec/image_size_spec.rb
CHANGED
@@ -81,4 +81,15 @@ describe ImageSize do
|
|
81
81
|
ImageSize.new(Object)
|
82
82
|
}.should raise_error(ArgumentError)
|
83
83
|
end
|
84
|
+
|
85
|
+
{
|
86
|
+
:png => "\211PNG\r\n\032\n",
|
87
|
+
:jpeg => "\377\330",
|
88
|
+
}.each do |type, data|
|
89
|
+
it "should raise FormatError if invalid #{type} given" do
|
90
|
+
lambda {
|
91
|
+
ImageSize.new(data)
|
92
|
+
}.should raise_error(ImageSize::FormatError)
|
93
|
+
end
|
94
|
+
end
|
84
95
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: image_size
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keisuke Minami
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-04-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|