image_size 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.travis.yml +7 -7
- data/CHANGELOG.markdown +4 -0
- data/Gemfile +2 -0
- data/image_size.gemspec +10 -3
- data/lib/image_size.rb +12 -2
- data/spec/image_size_spec.rb +2 -0
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0fa25bd1e135ab32ca6314351395d6244da802b7ab2e2453e4693a144ec59d8
|
4
|
+
data.tar.gz: 3132376fd6fb5e06230a72682c9129d7d5429513552a07ec1bd2086333eb4866
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eab18d5faae61455ed10c9a7a63eab394b0de1c6c808db0c5337ee8b87904f725ae6b55b1019c3da743171421a7401bc64b36bacc228be3b87e0d7de46338a25
|
7
|
+
data.tar.gz: d3009f25b1a73e0b9ae22c20e078e428869cc3cb79c7f7691b1886360a7aa5d75d0aa537643b65037d11d00dddba24104e68255489967ed4c6e030f0c78d6b60
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,24 +1,24 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
before_install:
|
4
|
-
- gem
|
4
|
+
- gem install bundler || gem install bundler --version '< 2'
|
5
5
|
rvm:
|
6
6
|
- '1.8.7-p371'
|
7
7
|
- '1.9.3-p551'
|
8
8
|
- '2.0.0-p648'
|
9
9
|
- '2.1.10'
|
10
10
|
- '2.2.10'
|
11
|
-
- '2.3.
|
12
|
-
- '2.4.
|
13
|
-
- '2.5.
|
14
|
-
- '
|
11
|
+
- '2.3.8'
|
12
|
+
- '2.4.6'
|
13
|
+
- '2.5.5'
|
14
|
+
- '2.6.3'
|
15
15
|
- 'jruby-9.1.9.0'
|
16
16
|
script: bundle exec rspec
|
17
17
|
matrix:
|
18
18
|
include:
|
19
19
|
- env: RUBOCOP=✓
|
20
|
-
rvm: '2.
|
20
|
+
rvm: '2.6.3'
|
21
21
|
script: bundle exec rubocop
|
22
22
|
- env: CHECK_RUBIES=✓
|
23
|
-
rvm: '2.
|
23
|
+
rvm: '2.6.3'
|
24
24
|
script: bundle exec travis_check_rubies
|
data/CHANGELOG.markdown
CHANGED
data/Gemfile
CHANGED
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 = '2.0.
|
5
|
+
s.version = '2.0.1'
|
6
6
|
s.summary = %q{Measure image size using pure Ruby}
|
7
7
|
s.description = %q{Measure following file dimensions: apng, bmp, cur, gif, jpeg, ico, mng, pbm, pcx, pgm, png, ppm, psd, swf, tiff, xbm, xpm, webp}
|
8
8
|
s.homepage = "http://github.com/toy/#{s.name}"
|
@@ -11,13 +11,20 @@ Gem::Specification.new do |s|
|
|
11
11
|
|
12
12
|
s.rubyforge_project = s.name
|
13
13
|
|
14
|
+
s.metadata = {
|
15
|
+
'bug_tracker_uri' => "https://github.com/toy/#{s.name}/issues",
|
16
|
+
'changelog_uri' => "https://github.com/toy/#{s.name}/blob/master/CHANGELOG.markdown",
|
17
|
+
'documentation_uri' => "https://www.rubydoc.info/gems/#{s.name}/#{s.version}",
|
18
|
+
'source_code_uri' => "https://github.com/toy/#{s.name}",
|
19
|
+
}
|
20
|
+
|
14
21
|
s.files = `git ls-files`.split("\n")
|
15
22
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
23
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
24
|
s.require_paths = %w[lib]
|
18
25
|
|
19
26
|
s.add_development_dependency 'rspec', '~> 3.0'
|
20
|
-
if RUBY_VERSION >= '2.
|
21
|
-
s.add_development_dependency 'rubocop', '~> 0.
|
27
|
+
if RUBY_VERSION >= '2.2'
|
28
|
+
s.add_development_dependency 'rubocop', '~> 0.59'
|
22
29
|
end
|
23
30
|
end
|
data/lib/image_size.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: BINARY
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'stringio'
|
4
5
|
|
@@ -24,7 +25,7 @@ class ImageSize
|
|
24
25
|
else
|
25
26
|
raise ArgumentError, "expected data as String or an object responding to read and eof?, got #{data_or_io.class}"
|
26
27
|
end
|
27
|
-
@data =
|
28
|
+
@data = String.new # not frozen
|
28
29
|
end
|
29
30
|
|
30
31
|
CHUNK = 1024
|
@@ -32,6 +33,7 @@ class ImageSize
|
|
32
33
|
while !@io.eof? && @data.length < offset + length
|
33
34
|
data = @io.read(CHUNK)
|
34
35
|
break unless data
|
36
|
+
|
35
37
|
data.force_encoding(@data.encoding) if data.respond_to?(:encoding)
|
36
38
|
@data << data
|
37
39
|
end
|
@@ -59,6 +61,7 @@ class ImageSize
|
|
59
61
|
ir = ImageReader.new(data)
|
60
62
|
@format = detect_format(ir)
|
61
63
|
return unless @format
|
64
|
+
|
62
65
|
@width, @height = send("size_of_#{@format}", ir)
|
63
66
|
end
|
64
67
|
|
@@ -80,7 +83,7 @@ class ImageSize
|
|
80
83
|
|
81
84
|
private
|
82
85
|
|
83
|
-
SVG_R = /<svg\b([^>]*)
|
86
|
+
SVG_R = /<svg\b([^>]*)>/.freeze
|
84
87
|
def detect_format(ir)
|
85
88
|
head = ir[0, 1024]
|
86
89
|
case
|
@@ -127,6 +130,7 @@ private
|
|
127
130
|
unless ir[12, 4] == 'MHDR'
|
128
131
|
raise FormatError, 'MHDR not in place for MNG'
|
129
132
|
end
|
133
|
+
|
130
134
|
ir[16, 8].unpack('NN')
|
131
135
|
end
|
132
136
|
|
@@ -134,6 +138,7 @@ private
|
|
134
138
|
unless ir[12, 4] == 'IHDR'
|
135
139
|
raise FormatError, 'IHDR not in place for PNG'
|
136
140
|
end
|
141
|
+
|
137
142
|
ir[16, 8].unpack('NN')
|
138
143
|
end
|
139
144
|
alias_method :size_of_apng, :size_of_png
|
@@ -158,6 +163,7 @@ private
|
|
158
163
|
if JPEG_CODE_CHECK.include?(code)
|
159
164
|
return ir[offset + 1, 4].unpack('nn').reverse
|
160
165
|
end
|
166
|
+
|
161
167
|
offset += length - 2
|
162
168
|
end
|
163
169
|
end
|
@@ -199,6 +205,7 @@ private
|
|
199
205
|
if data.length != length
|
200
206
|
raise FormatError, 'XPM size not found'
|
201
207
|
end
|
208
|
+
|
202
209
|
length += 1024
|
203
210
|
end
|
204
211
|
[$1.to_i, $2.to_i]
|
@@ -222,10 +229,12 @@ private
|
|
222
229
|
until width && height
|
223
230
|
ifd = ir[offset, 12]
|
224
231
|
raise FormatError, 'Reached end of directory entries in TIFF' if ifd.nil? || offset > num_dirent
|
232
|
+
|
225
233
|
tag, type = ifd.unpack(endian2b * 2)
|
226
234
|
offset += 12
|
227
235
|
|
228
236
|
next if packspec[type].nil?
|
237
|
+
|
229
238
|
value = ifd[8, 4].unpack(packspec[type])[0]
|
230
239
|
case tag
|
231
240
|
when 0x0100
|
@@ -259,6 +268,7 @@ private
|
|
259
268
|
dpi = self.class.dpi
|
260
269
|
[attributes['width'], attributes['height']].map do |length|
|
261
270
|
next unless length
|
271
|
+
|
262
272
|
pixels = case length.downcase.strip[/(?:em|ex|px|in|cm|mm|pt|pc|%)\z/]
|
263
273
|
when 'em', 'ex', '%' then nil
|
264
274
|
when 'in' then length.to_f * dpi
|
data/spec/image_size_spec.rb
CHANGED
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: 2.0.
|
4
|
+
version: 2.0.1
|
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:
|
12
|
+
date: 2019-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0.
|
34
|
+
version: '0.59'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0.
|
41
|
+
version: '0.59'
|
42
42
|
description: 'Measure following file dimensions: apng, bmp, cur, gif, jpeg, ico, mng,
|
43
43
|
pbm, pcx, pgm, png, ppm, psd, swf, tiff, xbm, xpm, webp'
|
44
44
|
email:
|
@@ -82,7 +82,11 @@ files:
|
|
82
82
|
homepage: http://github.com/toy/image_size
|
83
83
|
licenses:
|
84
84
|
- Ruby
|
85
|
-
metadata:
|
85
|
+
metadata:
|
86
|
+
bug_tracker_uri: https://github.com/toy/image_size/issues
|
87
|
+
changelog_uri: https://github.com/toy/image_size/blob/master/CHANGELOG.markdown
|
88
|
+
documentation_uri: https://www.rubydoc.info/gems/image_size/2.0.1
|
89
|
+
source_code_uri: https://github.com/toy/image_size
|
86
90
|
post_install_message:
|
87
91
|
rdoc_options: []
|
88
92
|
require_paths:
|
@@ -98,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
102
|
- !ruby/object:Gem::Version
|
99
103
|
version: '0'
|
100
104
|
requirements: []
|
101
|
-
|
102
|
-
rubygems_version: 2.7.6
|
105
|
+
rubygems_version: 3.0.3
|
103
106
|
signing_key:
|
104
107
|
specification_version: 4
|
105
108
|
summary: Measure image size using pure Ruby
|