Browse Source

Initial commit

master
ポール ウェッブ 5 months ago
parent
commit
2c13d7ba65
5 changed files with 114 additions and 32 deletions
  1. 0
    10
      .gitignore
  2. 6
    21
      LICENSE
  3. 39
    1
      README.md
  4. 10
    0
      Skin colors.txt
  5. 59
    0
      emoji_extractor.rb

+ 0
- 10
.gitignore View File

@@ -1,13 +1,3 @@
1
-# ---> Default
2 1
 # Files
3 2
 .DS_Store
4
-.env
5
-*.log
6
-*.lock
7 3
 Thumbs.db
8
-
9
-# Directories
10
-.cache
11
-.sass-cache
12
-node_modules
13
-

+ 6
- 21
LICENSE View File

@@ -1,26 +1,11 @@
1
-Copyright (c) <year> <owner> . All rights reserved.
1
+Copyright © 2019 Paul Anthony Webb. All rights reserved.
2 2
 
3
-Redistribution and use in source and binary forms, with or without modification,
4
-are permitted provided that the following conditions are met:
3
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5 4
 
6
-1. Redistributions of source code must retain the above copyright notice,
7
-this list of conditions and the following disclaimer.
5
+1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 6
 
9
-2. Redistributions in binary form must reproduce the above copyright notice,
10
-this list of conditions and the following disclaimer in the documentation
11
-and/or other materials provided with the distribution.
7
+2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
12 8
 
13
-3. Neither the name of the copyright holder nor the names of its contributors
14
-may be used to endorse or promote products derived from this software without
15
-specific prior written permission.
9
+3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
16 10
 
17
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22
-DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23
-SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24
-CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26
-USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
11
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

+ 39
- 1
README.md View File

@@ -1,3 +1,41 @@
1 1
 # emoji-extractor
2 2
 
3
-> Extracts high-resolution emoji PNGs from /System/Library/Fonts/Apple Color Emoji.ttc
3
+> Extracts high-resolution emoji PNGs from `/System/Library/Fonts/Apple Color Emoji.ttc`
4
+
5
+This is a small ruby script that extracts the Apple Color Emoji PNG Symbols from their corresponding system font located at `/System/Library/Fonts/Apple Color Emoji.ttc`.
6
+
7
+The extracted assets will be placed in a subfolder of one called "images", for each resolution in their own folder. File system structure is as follows:
8
+
9
+```
10
+.
11
+├── README.md
12
+├── emoji_extractor.rb
13
+└── images
14
+    ├── 20x20
15
+    ├── 21x21
16
+    ├── 32x32
17
+    ├── 40x40
18
+    ├── 48x48
19
+    ├── 64x64
20
+    ├── 96x96
21
+    └── 160x160
22
+```
23
+
24
+
25
+
26
+## Test
27
+
28
+Make sure the font exists. The response should look like the second line:
29
+
30
+```
31
+$ file /System/Library/Fonts/Apple\ Color\ Emoji.ttc
32
+/System/Library/Fonts/Apple Color Emoji.ttc: TrueType font collection data, 2.0, 2 fonts, at 0x20 TrueType Font data, 16 tables, 1st "OS/2"
33
+```
34
+
35
+
36
+
37
+## Usage
38
+
39
+```
40
+$ ruby emoji_extractor.rb
41
+```

+ 10
- 0
Skin colors.txt View File

@@ -0,0 +1,10 @@
1
+=========================
2
+=== Apple Color Emoji ===
3
+====== Skin Colors ======
4
+=========================
5
+Yellow
6
+White
7
+Light Skinned
8
+Light Intermediate
9
+Dark Intermediate
10
+Black

+ 59
- 0
emoji_extractor.rb View File

@@ -0,0 +1,59 @@
1
+# encoding: US-ASCII
2
+# forked from https://github.com/LukeLR/emoji-extractor
3
+
4
+require "stringio"
5
+require "fileutils"
6
+
7
+def extract_chunk(input, output)
8
+  lenword = input.read(4)
9
+  length = lenword.unpack('N')[0]
10
+  type = input.read(4)
11
+  data = length>0 ? input.read(length) : ""
12
+  crc = input.read(4)
13
+  return nil if length<0 || !(('A'..'z')===type[0,1])
14
+  #return nil if validate_crc(type+data, crc)
15
+  output.write lenword
16
+  output.write type
17
+  output.write data
18
+  output.write crc
19
+  return [type, data]
20
+end
21
+
22
+def extract_png(input)
23
+  buf = StringIO.new
24
+  hdr = input.read(8)
25
+  raise "Not a PNG File" if hdr[0,4]!= "\211PNG"
26
+  raise "file not in binary mode" if hdr[4,4]!="\r\n\032\n"
27
+  buf.write(hdr)
28
+
29
+  height, width = 0, 0
30
+
31
+  loop do
32
+    chunk_type, chunk_data = extract_chunk(input,buf)
33
+    height, width = chunk_data.unpack("NN") if chunk_type == "IHDR"
34
+    break if  chunk_type.nil? || chunk_type == "IEND"
35
+  end
36
+
37
+  FileUtils.mkdir_p(dir = "images/#{height}x#{width}")
38
+  if @prev != dir
39
+    @n = 0
40
+    @prev = dir
41
+  end
42
+
43
+  buf.rewind
44
+  ofp = File.new("#{dir}/#{@n+=1}.png","wb")
45
+  ofp.write buf.read
46
+  ofp.close
47
+end
48
+
49
+ttf = File.new("/System/Library/Fonts/Apple Color Emoji.ttc", "rb")
50
+ttf_data = ttf.read
51
+
52
+pos = 0
53
+while m = /\211PNG/.match(ttf_data[pos..-1])
54
+  raise "no PNG found" if !m
55
+  pos += m.begin(0) + 1
56
+  ttf.seek(pos-1)
57
+
58
+  extract_png(ttf)
59
+end

Loading…
Cancel
Save