Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Facebook/Messenger images #76

Merged
merged 27 commits into from
Mar 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7854140
Create facebook/grab.php
Crissov Mar 9, 2017
e52598d
Create facebook/make64.php
Crissov Mar 9, 2017
d7c626b
Create facebook/readme.md
Crissov Mar 9, 2017
66693f3
Update README.md
Crissov Mar 9, 2017
0d3b10f
add Facebook to build_sheets.php
Crissov Mar 10, 2017
7846a92
Update build_table for Facebook
Crissov Mar 10, 2017
bcd6f94
Update find_flags.php for Facebook
Crissov Mar 10, 2017
bb819fb
Update find_unused.php for Facebook
Crissov Mar 10, 2017
4ff2e80
Update quant_sheets.sh for Facebook
Crissov Mar 10, 2017
0d01298
Update README.md for Facebook
Crissov Mar 10, 2017
ea6cab7
modified facebook grab script to pull down messenger images
iamcal Mar 10, 2017
a564698
updated build instructions
iamcal Mar 10, 2017
5186853
facebook and messenger are two distinct image sets
iamcal Mar 10, 2017
48afe25
rebuild map and tables for facebook & messenger
iamcal Mar 10, 2017
0037427
change log
iamcal Mar 10, 2017
cc69a96
we've been using Nougat images since the 2016-11-11 release
iamcal Mar 10, 2017
bfa3039
more missing images for messenger
iamcal Mar 10, 2017
535a05c
this will now land in #76
iamcal Mar 10, 2017
a8f4084
more missing images
iamcal Mar 10, 2017
6724f33
the missing images
iamcal Mar 11, 2017
3db1969
* only fetch with underscores instead of dashes
iamcal Mar 11, 2017
0e64f66
all the missing FB images
iamcal Mar 11, 2017
ce7a4fe
rebuild with latest messenger images
iamcal Mar 11, 2017
74c4b49
run much faster with `parallel`
iamcal Mar 11, 2017
c17b483
optimized sheets for messenger
iamcal Mar 11, 2017
8a5e27f
optimized individual images
iamcal Mar 11, 2017
2a08c69
cleanup
iamcal Mar 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Change Log

## 2017-??-?? : v2.?
## 2017-??-?? : v2.5

* Made the kissing emoticons (e.g. :*) result in `kissing_heart` instead of `kiss` https://github.com/iamcal/emoji-data/pull/73
* Added support for Facebook and FB Messenger images. Only messenger currently has any images https://github.com/iamcal/emoji-data/pull/76
* ?

## 2016-11-11 : v2.4.5

Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ images for use on the web.

You can see a catalog of the emoji data here: http://unicodey.com/emoji-data/table.htm

## Image Sources

Images are extracted from their sources and this library attempts to track the latest
available versions. If you're looking for older versions of Apple of Android images
available versions. If you're looking for older versions of Apple or Android images
(such as the Hairy Heart) then you'll need to look at previous revisions.

* Apple Emoji: Copyright © Apple Inc. - OS X 10.11.1
* Android Emoji: Copyright © [The Android Open Source Project](https://s3-eu-west-1.amazonaws.com/tw-font/android/NOTICE) - Lollipop
* Twitter Emoji Copyright © Twitter, Inc. - The original release
* Android Emoji: Copyright © [The Android Open Source Project](https://s3-eu-west-1.amazonaws.com/tw-font/android/NOTICE) - Nougat
* Twitter Emoji: Copyright © Twitter, Inc. - The original release
* Emoji One Emoji: Copyright © [Ranks.com Inc.](http://www.emojione.com/developers) - master as of 2015-03-05
* Facebook/Messenger Emoji: Copyright © Facebook, Inc. - v7

## Libraries which use this data

Expand Down Expand Up @@ -54,6 +57,8 @@ look like this:
"has_img_google": true,
"has_img_twitter": true,
"has_img_emojione": false,
"has_img_facebook": false,
"has_img_messenger": false,
"skin_variations": {
"261D-1F3FB": {
"unified": "261D-1F3FB",
Expand All @@ -64,6 +69,8 @@ look like this:
"has_img_google": false,
"has_img_twitter": false,
"has_img_emojione": false
"has_img_facebook": false
"has_img_messenger": false
},
...
}
Expand Down
2 changes: 2 additions & 0 deletions build/build_image.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
create_sheet('twitter');
create_sheet('google');
create_sheet('emojione');
create_sheet('facebook');
create_sheet('messenger');


function create_sheet($type){
Expand Down
4 changes: 4 additions & 0 deletions build/build_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ function simple_row($img_key, $shorts, $props){
$ret['has_img_google'] = file_exists("{$GLOBALS['dir']}/../img-google-64/{$ret['image']}");
$ret['has_img_twitter'] = file_exists("{$GLOBALS['dir']}/../img-twitter-64/{$ret['image']}");
$ret['has_img_emojione'] = file_exists("{$GLOBALS['dir']}/../img-emojione-64/{$ret['image']}");
$ret['has_img_facebook'] = file_exists("{$GLOBALS['dir']}/../img-facebook-64/{$ret['image']}");
$ret['has_img_messenger'] = file_exists("{$GLOBALS['dir']}/../img-messenger-64/{$ret['image']}");

foreach ($props as $k => $v) $ret[$k] = $v;

Expand All @@ -406,6 +408,8 @@ function simple_row($img_key, $shorts, $props){
'has_img_google' => file_exists("{$GLOBALS['dir']}/../img-google-64/{$var_img}"),
'has_img_twitter' => file_exists("{$GLOBALS['dir']}/../img-twitter-64/{$var_img}"),
'has_img_emojione' => file_exists("{$GLOBALS['dir']}/../img-emojione-64/{$var_img}"),
'has_img_facebook' => file_exists("{$GLOBALS['dir']}/../img-facebook-64/{$var_img}"),
'has_img_messenger' => file_exists("{$GLOBALS['dir']}/../img-messenger-64/{$var_img}"),
);

$ret['skin_variations'][$var_uni] = $variation;
Expand Down
21 changes: 7 additions & 14 deletions build/build_sheets.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<?php
$dir = dirname(__FILE__).'/..';

build_sheet('apple', 32);
build_sheet('apple', 20);
build_sheet('apple', 16);
$sets = array('apple', 'twitter', 'google', 'emojione', 'facebook', 'messenger');
$sizes = array(16, 20, 32);

build_sheet('twitter', 32);
build_sheet('twitter', 20);
build_sheet('twitter', 16);

build_sheet('google', 32);
build_sheet('google', 20);
build_sheet('google', 16);

build_sheet('emojione', 32);
build_sheet('emojione', 20);
build_sheet('emojione', 16);
foreach ($sets as $set) {
foreach ($sizes as $size) {
build_sheet($set, $size);
}
}

function build_sheet($type, $size){

Expand Down
22 changes: 12 additions & 10 deletions build/build_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
$in = file_get_contents('../emoji.json');
$catalog = json_decode($in, true);


function format_codepoints($raw){

if (!$raw) return '-';
Expand Down Expand Up @@ -54,19 +53,18 @@ function emoji_utf8_bytes($cp){
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta charset="UTF-8" />
<title>Emoji Catalog</title>
<link rel="stylesheet" type="text/css" media="all" href="emoji.css" />
<style type="text/css">

body {
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
}

table {
-webkit-border-radius: 0.41em;
-moz-border-radius: 0.41em;
border-radius: 0.41em;
border: 1px solid #999;
font-size: 12px;
}
Expand Down Expand Up @@ -101,7 +99,7 @@ function emoji_utf8_bytes($cp){

<table cellspacing="0" cellpadding="0">
<tr>
<th colspan="6">Name</th>
<th colspan="8">Name</th>
<th>Short Name</th>
<th>ASCII</th>
<th>Unified</th>
Expand All @@ -117,16 +115,20 @@ function emoji_utf8_bytes($cp){
<?php
foreach ($catalog as $row){

$url_apple = $row['has_img_apple' ] ? "img-apple-64/{$row['image']}" : '';
$url_google = $row['has_img_google' ] ? "img-google-64/{$row['image']}" : '';
$url_twitter = $row['has_img_twitter' ] ? "img-twitter-64/{$row['image']}" : '';
$url_emojione = $row['has_img_emojione'] ? "img-emojione-64/{$row['image']}" : '';
$url_apple = $row['has_img_apple' ] ? "img-apple-64/{$row['image']}" : '';
$url_google = $row['has_img_google' ] ? "img-google-64/{$row['image']}" : '';
$url_twitter = $row['has_img_twitter' ] ? "img-twitter-64/{$row['image']}" : '';
$url_emojione = $row['has_img_emojione' ] ? "img-emojione-64/{$row['image']}" : '';
$url_facebook = $row['has_img_facebook' ] ? "img-facebook-64/{$row['image']}" : '';
$url_messenger = $row['has_img_messenger'] ? "img-messenger-64/{$row['image']}" : '';

echo "\t<tr>\n";
echo "\t\t<td><img src=\"{$url_apple}\" width=\"20\" height=\"20\" /></td>\n";
echo "\t\t<td><img src=\"{$url_google}\" width=\"20\" height=\"20\" /></td>\n";
echo "\t\t<td><img src=\"{$url_twitter}\" width=\"20\" height=\"20\" /></td>\n";
echo "\t\t<td><img src=\"{$url_emojione}\" width=\"20\" height=\"20\" /></td>\n";
echo "\t\t<td><img src=\"{$url_facebook}\" width=\"20\" height=\"20\" /></td>\n";
echo "\t\t<td><img src=\"{$url_messenger}\" width=\"20\" height=\"20\" /></td>\n";
echo "\t\t<td>".unicode_bytes($row['unified'])."</td>\n";
echo "\t\t<td>".HtmlSpecialChars(StrToLower($row['name']))."</td>\n";

Expand Down
19 changes: 19 additions & 0 deletions build/facebook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Building the Facebook emoji images

From any machine:

php grab.php

This will fetch the 128px versions of all available emoji.

Next you'll want to cut the 64px versions that are used in the sheets:

php make64.php

And finally optimize them. This requires the optimizing tools in `build/README.md` to be installed
and takes a very long time:

parallel ../optimize.sh ::: ../../img-facebook-64/*
parallel ../optimize.sh ::: ../../img-messenger-64/*

The resulting 64px images are then ready to use.
164 changes: 164 additions & 0 deletions build/facebook/grab.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?php

$json = file_get_contents('../../emoji.json');
$data = json_decode($json, true);

# comment these out to do incremental download
#shell_exec("rm -f ../../img-messenger-128/*.png");
#shell_exec("rm -f ../../img-facebook-128/*.png");


foreach ($data as $row){
if (strlen($row['image'])){
fetch($row['image']);
}

if (isset($row['skin_variations'])){
foreach ($row['skin_variations'] as $row2){
fetch($row2['image']);
}
}
}

function fetch($img){
fetch_single($img, 'MESSENGER', 'img-messenger-128', 128);
#fetch_single($img, 'FBEMOJI', 'img-facebook-72', 72);
}


function fetch_single($img, $type_key, $dir, $size){
/* based upon Twitter scraper and Javascript from Facebook see Github issue #56 */

# files get stored here
$path = "../../{$dir}/{$img}";

# use this for just fetching missing images
if (file_exists($path)) return;

# Emoji Config
$supportedSizes = [16, 18, 20, 24, 28, 30, 32, 64, 128];
$types = array('FBEMOJI' => 'f', 'FB_EMOJI_EXTENDED' => 'e', 'MESSENGER' => 'z', 'UNICODE' => 'u');

$type = $types[$type_key];


# emoji.img = acbd-1234.png
# facebook = abcd_1234.png

$url = build_url($type, $size, str_replace('-', '_', $img));

if (try_fetch($url, $path)){
echo '.';
return;
}

#echo "X[{$img}]";
echo 'X';
#sleep(1);
}


function build_url($type, $size, $img){

$pixelRatio = 1;
$schemaAuth = "https://www.facebook.com/images/emoji.php/v7";

$path = $pixelRatio . '/' . $size . '/' . $img;
$check = checksum($path);
$url = $schemaAuth . '/' . $type . $check . '/' . $path;

return $url;
}

function try_fetch($url, $path){

http_fetch($url, $path);

if (!file_exists($path)){
return false;
}

if (!filesize($path)){
@unlink($path);
return false;
}

# PNG signature?
$fp = fopen($path, 'r');
$sig = fread($fp, 4);
fclose($fp);

if ($sig != "\x89PNG"){
#print_r($sig);
@unlink($path);
return false;
}

# ok!
return true;
}
function encodeURIComponent($str) { /* a standard method in Javascript */
return $str;
}
function unescape($str) {
$trans = array('&amp;' => '&', '&lt;' => '<', '&gt;' => '>', '&quot;' => '"', '&#x27;' => "'");
return strtr($str, $trans);
}
function checksum($subpath) {
$checksumBase = 317426846;
$base = $checksumBase;
// $subpath = unescape(encodeURIComponent($subpath));
for ($pos = 0; $pos < strlen($subpath); $pos++) {
$base = ($base << 5) - $base + ord(substr($subpath, $pos, 1));
$base &= 4294967295;
}
return base_convert(($base & 255), 10, 16);
}


function http_fetch($url, $filename){

$fh = fopen($filename, 'w');

$options = array(
CURLOPT_FILE => $fh,
CURLOPT_TIMEOUT => 60,
CURLOPT_URL => $url,
);

$options[CURLOPT_HTTPHEADER] = array(
'Referer: https://www.facebook.com/',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
);

$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
$ret = curl_getinfo($ch);
curl_close($ch);

fclose($fh);

# show http error code?
#echo "({$ret['http_code']})";

#print_r($ret);
#exit;
}


function http_fetch_old($url, $filename){

$out = array();
$ret = 0;
exec("wget -qO {$filename} \"{$url}\"", $out, $ret);

# error from wget?
if ($ret){
#print_r($out);
@unlink($path);
return false;
}

return true;
}
21 changes: 21 additions & 0 deletions build/facebook/make64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
thumb_set('img-messenger-128', 'img-messenger-64');


function thumb_set($from, $to){

$files = glob("../../{$from}/*.png");
shell_exec("rm -f ../../{$to}/*.png");
foreach ($files as $src){
$bits = explode('/', $src);
$dst = "../../{$to}/".array_pop($bits);
exec("convert {$src} -resize 64x64 png32:{$dst}", $out, $code);
if ($code){
echo "ERROR:\n";
echo " ".$out."\n";
}else{
echo ".";
}
}
echo "All done\n";
}
4 changes: 3 additions & 1 deletion build/find_flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
$b = find_flags("../img-google-64/1f1*-1f1*.png");
$c = find_flags("../img-twitter-64/1f1*-1f1*.png");
$d = find_flags("../img-emojione-64/1f1*-1f1*.png");
$e = find_flags("../img-facebook-64/1f1*-1f1*.png");
$f = find_flags("../img-messenger-64/1f1*-1f1*.png");

$all = array_unique(array_merge($a, $b, $c, $d));
$all = array_unique(array_merge($a, $b, $c, $d, $e, $f));
sort($all);

foreach ($all as $line) echo $line;
Expand Down
2 changes: 2 additions & 0 deletions build/find_unused.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
scan_unused($files, '../img-google-64/');
scan_unused($files, '../img-twitter-64/');
scan_unused($files, '../img-emojione-64/');
scan_unused($files, '../img-facebook-64/');
scan_unused($files, '../img-messenger-64/');
echo "~FIN~\n";

function scan_unused($files, $path){
Expand Down
Loading