icns 0.1.0 → 0.2.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 +5 -5
- data/.rubocop.yml +12 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -2
- data/Gemfile +5 -1
- data/Gemfile.lock +21 -2
- data/README.md +7 -4
- data/Rakefile +8 -6
- data/icns.gemspec +4 -3
- data/lib/icns.rb +8 -8
- data/lib/icns/errors.rb +2 -0
- data/lib/icns/reader.rb +29 -24
- data/lib/icns/version.rb +1 -1
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73af1cb7701d4470b180246ec9c13dd6ecb6b72df1f5154874a1717c40fc8c40
|
4
|
+
data.tar.gz: 7ae0fa54528d9b01662fd86906b56d6d1c6c328ab1e3cc0246d4e4f495b35dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc9f61bad74d25a699c0e1a592040a159e73351b565e7f98ed18d0e8604a32109c75a529c618526f6e998453d081595f0ce21ae534afe522db23c7ae9f6f0ebe
|
7
|
+
data.tar.gz: df524a7ba9b7713304f2b15f8b8679b832516ceaf5e235be2041b3b8c97079592c01cfe15253d5233b524f178729c87cdb8d59ffb359a60c4c00c8390e123fff
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,13 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
icns (0.
|
4
|
+
icns (0.2.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
ast (2.4.0)
|
9
10
|
minitest (5.11.3)
|
11
|
+
parallel (1.12.1)
|
12
|
+
parser (2.5.1.0)
|
13
|
+
ast (~> 2.4.0)
|
14
|
+
powerpack (0.1.1)
|
15
|
+
rainbow (3.0.0)
|
10
16
|
rake (10.5.0)
|
17
|
+
rubocop (0.56.0)
|
18
|
+
parallel (~> 1.10)
|
19
|
+
parser (>= 2.5)
|
20
|
+
powerpack (~> 0.1)
|
21
|
+
rainbow (>= 2.2.2, < 4.0)
|
22
|
+
ruby-progressbar (~> 1.7)
|
23
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
24
|
+
ruby-progressbar (1.9.0)
|
25
|
+
unicode-display_width (1.3.2)
|
11
26
|
|
12
27
|
PLATFORMS
|
13
28
|
ruby
|
@@ -17,6 +32,10 @@ DEPENDENCIES
|
|
17
32
|
icns!
|
18
33
|
minitest (~> 5.0)
|
19
34
|
rake (~> 10.0)
|
35
|
+
rubocop (~> 0.56)
|
36
|
+
|
37
|
+
RUBY VERSION
|
38
|
+
ruby 2.5.1p57
|
20
39
|
|
21
40
|
BUNDLED WITH
|
22
|
-
1.16.
|
41
|
+
1.16.2
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
#
|
1
|
+
# ICNS
|
2
2
|
|
3
|
-
|
3
|
+
[](http://rubygems.org/gems/icns)
|
4
|
+
[](https://travis-ci.com/soffes/icns)
|
5
|
+
|
6
|
+
Ruby library for extrating images from [Apple Icon Image format (ICNS)](https://en.wikipedia.org/wiki/Apple_Icon_Image_format) files.
|
4
7
|
|
5
8
|
|
6
9
|
## Installation
|
@@ -28,10 +31,10 @@ Read an icon out of an ICNS file:
|
|
28
31
|
require 'icns'
|
29
32
|
|
30
33
|
# Create a reader for an ICNS file
|
31
|
-
reader = Icns::Reader('/Applications/Preview.app/Contents/Resources/Preview.icns')
|
34
|
+
reader = Icns::Reader.new('/Applications/Preview.app/Contents/Resources/Preview.icns')
|
32
35
|
|
33
36
|
# Extract the image data for a given size
|
34
|
-
data = reader.
|
37
|
+
data = reader.image(size: 1024)
|
35
38
|
|
36
39
|
# Write the image data out or do whatever you want with it
|
37
40
|
File.write('Preview.png', data)
|
data/Rakefile
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rake/testtask'
|
3
5
|
|
4
6
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
7
|
-
t.test_files = FileList[
|
7
|
+
t.libs << 'test'
|
8
|
+
t.libs << 'lib'
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
8
10
|
end
|
9
11
|
|
10
|
-
task :
|
12
|
+
task default: :test
|
data/icns.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path('
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
5
|
require 'icns/version'
|
6
6
|
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.version = Icns::VERSION
|
10
10
|
spec.authors = ['Sam Soffes']
|
11
11
|
spec.email = ['sam@soff.es']
|
12
|
-
spec.summary = '
|
12
|
+
spec.summary = 'Read images from Apple Icon Image format (ICNS) files.'
|
13
13
|
spec.homepage = 'https://github.com/soffes/icns'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.16'
|
22
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
23
22
|
spec.add_development_dependency 'minitest', '~> 5.0'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rubocop', '~> 0.56'
|
24
25
|
end
|
data/lib/icns.rb
CHANGED
@@ -106,12 +106,12 @@ module Icns
|
|
106
106
|
|
107
107
|
# Types to try for each size
|
108
108
|
SIZE_TO_TYPE = {
|
109
|
-
16 => %w
|
110
|
-
32 => %w
|
111
|
-
64 => %w
|
112
|
-
128 => %w
|
113
|
-
256 => %w
|
114
|
-
512 => %w
|
115
|
-
1024 => %w
|
116
|
-
}
|
109
|
+
16 => %w[icp4],
|
110
|
+
32 => %w[icp5 ic11],
|
111
|
+
64 => %w[icp6 ic12],
|
112
|
+
128 => %w[ic07],
|
113
|
+
256 => %w[ic08 ic13],
|
114
|
+
512 => %w[ic09 ic14],
|
115
|
+
1024 => %w[ic10]
|
116
|
+
}.freeze
|
117
117
|
end
|
data/lib/icns/errors.rb
CHANGED
data/lib/icns/reader.rb
CHANGED
@@ -3,10 +3,11 @@
|
|
3
3
|
require 'icns/errors'
|
4
4
|
|
5
5
|
module Icns
|
6
|
+
# Read an ICNS file’s metadata and extract images.
|
6
7
|
class Reader
|
7
8
|
# Initialize with a path to a valid ICNS file
|
8
9
|
def initialize(path)
|
9
|
-
throw FileNotFound unless File.
|
10
|
+
throw FileNotFound unless File.exist?(path)
|
10
11
|
|
11
12
|
@path = path
|
12
13
|
@parts = {}
|
@@ -20,8 +21,8 @@ module Icns
|
|
20
21
|
end
|
21
22
|
|
22
23
|
# Raw data for a type
|
23
|
-
def
|
24
|
-
return nil unless part = @parts[type.to_s]
|
24
|
+
def data(type:)
|
25
|
+
return nil unless (part = @parts[type.to_s])
|
25
26
|
|
26
27
|
File.open(@path) do |file|
|
27
28
|
# Seek to the image data position
|
@@ -33,12 +34,12 @@ module Icns
|
|
33
34
|
end
|
34
35
|
|
35
36
|
# PNG or JPEG-2000 data for a size
|
36
|
-
def
|
37
|
-
return nil unless types = SIZE_TO_TYPE[size.to_i]
|
37
|
+
def image(size:)
|
38
|
+
return nil unless (types = SIZE_TO_TYPE[size.to_i])
|
38
39
|
|
39
40
|
data = nil
|
40
41
|
types.each do |type|
|
41
|
-
break if data =
|
42
|
+
break if (data = self.data(type: type))
|
42
43
|
end
|
43
44
|
|
44
45
|
data
|
@@ -47,8 +48,8 @@ module Icns
|
|
47
48
|
# Available image sizes
|
48
49
|
def sizes
|
49
50
|
types = SIZE_TO_TYPE.values.flatten
|
50
|
-
@parts.keys.select { |k| types.include?(k) }
|
51
|
-
|
51
|
+
@parts.keys.select { |k| types.include?(k) }
|
52
|
+
.map { |k| TYPE_TO_SIZE[k] }.sort.uniq
|
52
53
|
end
|
53
54
|
|
54
55
|
private
|
@@ -74,24 +75,28 @@ module Icns
|
|
74
75
|
file.pos += 4
|
75
76
|
|
76
77
|
# Keep reading until we hit the end
|
77
|
-
|
78
|
-
|
79
|
-
break unless (type = file.read(4)) && (length = file.read(4))
|
80
|
-
|
81
|
-
# Convert the length into an integer. The length includes the icon
|
82
|
-
# header. We just want the length of the image data.
|
83
|
-
length = length.unpack('N')[0] - 8
|
84
|
-
|
85
|
-
unless TYPES_BLACKLIST.include?(type)
|
86
|
-
# Add to our hash of type name to image data locations
|
87
|
-
puts "WARNING: duplicate part '#{type}'" if @parts[type]
|
88
|
-
@parts[type] = { offset: file.pos, length: length }
|
89
|
-
end
|
90
|
-
|
91
|
-
# Advance past the image data
|
92
|
-
file.pos += length
|
78
|
+
loop do
|
79
|
+
break unless read_part(file)
|
93
80
|
end
|
94
81
|
end
|
95
82
|
end
|
83
|
+
|
84
|
+
def read_part(file)
|
85
|
+
# If we can't read the icon type and length, we’re at the end
|
86
|
+
return false unless (type = file.read(4)) && (length = file.read(4))
|
87
|
+
|
88
|
+
# Convert the length into an integer. The length includes the icon
|
89
|
+
# header. We just want the length of the image data.
|
90
|
+
length = length.unpack1('N') - 8
|
91
|
+
|
92
|
+
unless TYPES_BLACKLIST.include?(type)
|
93
|
+
# Add to our hash of type name to image data locations
|
94
|
+
puts "WARNING: duplicate part '#{type}'" if @parts[type]
|
95
|
+
@parts[type] = { offset: file.pos, length: length }
|
96
|
+
end
|
97
|
+
|
98
|
+
# Advance past the image data
|
99
|
+
file.pos += length
|
100
|
+
end
|
96
101
|
end
|
97
102
|
end
|
data/lib/icns/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Soffes
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,19 +53,19 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rubocop
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
61
|
+
version: '0.56'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '0.56'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- sam@soff.es
|
@@ -60,6 +74,8 @@ extensions: []
|
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
76
|
- ".gitignore"
|
77
|
+
- ".rubocop.yml"
|
78
|
+
- ".ruby-version"
|
63
79
|
- ".travis.yml"
|
64
80
|
- Gemfile
|
65
81
|
- Gemfile.lock
|
@@ -93,8 +109,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
109
|
version: '0'
|
94
110
|
requirements: []
|
95
111
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.6
|
112
|
+
rubygems_version: 2.7.6
|
97
113
|
signing_key:
|
98
114
|
specification_version: 4
|
99
|
-
summary:
|
115
|
+
summary: Read images from Apple Icon Image format (ICNS) files.
|
100
116
|
test_files: []
|