discourse/lib/tasks/emoji.rake

64 lines
13 KiB
Ruby
Raw Normal View History

desc "update emoji images"
task "emoji:update" => :environment do
download_emojis_for("emoji_one", "https://raw.githubusercontent.com/Ranks/emojione/master/assets/png/%s.png", uppercase: true, leading_zeros: true)
download_emojis_for("twitter", "https://raw.githubusercontent.com/twitter/twemoji/gh-pages/72x72/%s.png", lowercase: true)
download_emojis_for("apple", "https://raw.githubusercontent.com/github/gemoji/master/images/emoji/unicode/%s.png", lowercase: true, leading_zeros: true)
# download_google_emojis("~/Desktop/images/%s.png")
end
def download_emojis_for(set, url_template, options={})
puts "Downloading emojis for #{set}..."
2014-12-22 18:12:26 -06:00
path = "public/images/emoji/#{set}"
FileUtils.rm_rf(path) rescue nil
FileUtils.mkdir_p(path) rescue nil
uppercase = options[:uppercase] == true
lowercase = options[:lowercase] == true
leading_zeros = options[:leading_zeros] == true
Emoji.all.each do |emoji|
codepoints = emoji["emoji"].codepoints.map { |c| c.to_s(16).rjust(leading_zeros ? 4 : 0, '0') }
filename = codepoints.join('-').sub(/-fe0f\b/, '')
filename = filename.downcase if lowercase
filename = filename.upcase if uppercase
puts "#{filename} -> #{emoji["emoji"]}"
url = url_template % filename
data = open(url).read rescue nil
next if data.nil?
FileUtils.cd(path) do
emoji["aliases"].each do |name|
File.open("#{name}.png", "wb") { |f| f << data }
2015-05-28 21:39:55 -05:00
ImageOptim.new.optimize_image!("#{name}.png")
end
end
end
end
# extracted from the NotoColorEmoji font
2015-04-29 16:33:25 -05:00
GOOGLE_EMOJIS ||= {35=>1, 48=>2, 49=>3, 50=>4, 51=>5, 52=>6, 53=>7, 54=>8, 55=>9, 56=>10, 57=>11, 169=>12, 174=>13, 8252=>14, 8265=>15, 8419=>16, 8482=>17, 8505=>18, 8596=>19, 8597=>20, 8598=>21, 8599=>22, 8600=>23, 8601=>24, 8617=>25, 8618=>26, 8986=>27, 8987=>28, 9193=>29, 9194=>30, 9195=>31, 9196=>32, 9200=>33, 9203=>34, 9410=>35, 9642=>36, 9643=>37, 9654=>38, 9664=>39, 9723=>40, 9724=>41, 9725=>42, 9726=>43, 9728=>44, 9729=>45, 9742=>46, 9745=>47, 9748=>48, 9749=>49, 9757=>50, 9786=>51, 9800=>52, 9801=>53, 9802=>54, 9803=>55, 9804=>56, 9805=>57, 9806=>58, 9807=>59, 9808=>60, 9809=>61, 9810=>62, 9811=>63, 9824=>64, 9827=>65, 9829=>66, 9830=>67, 9832=>68, 9851=>69, 9855=>70, 9875=>71, 9888=>72, 9889=>73, 9898=>74, 9899=>75, 9917=>76, 9918=>77, 9924=>78, 9925=>79, 9934=>80, 9940=>81, 9962=>82, 9970=>83, 9971=>84, 9973=>85, 9978=>86, 9981=>87, 9986=>88, 9989=>89, 9992=>90, 9993=>91, 9994=>92, 9995=>93, 9996=>94, 9999=>95, 10002=>96, 10004=>97, 10006=>98, 10024=>99, 10035=>100, 10036=>101, 10052=>102, 10055=>103, 10060=>104, 10062=>105, 10067=>106, 10068=>107, 10069=>108, 10071=>109, 10084=>110, 10133=>111, 10134=>112, 10135=>113, 10145=>114, 10160=>115, 10175=>116, 10548=>117, 10549=>118, 11013=>119, 11014=>120, 11015=>121, 11035=>122, 11036=>123, 11088=>124, 11093=>125, 12336=>126, 12349=>127, 12951=>128, 12953=>129, 126980=>130, 127183=>131, 127344=>132, 127345=>133, 127358=>134, 127359=>135, 127374=>136, 127377=>137, 127378=>138, 127379=>139, 127380=>140, 127381=>141, 127382=>142, 127383=>143, 127384=>144, 127385=>145, 127386=>146, 127462=>147, 127463=>148, 127464=>149, 127465=>150, 127466=>151, 127467=>152, 127468=>153, 127469=>154, 127470=>155, 127471=>156, 127472=>157, 127473=>158, 127474=>159, 127475=>160, 127476=>161, 127477=>162, 127478=>163, 127479=>164, 127480=>165, 127481=>166, 127482=>167, 127483=>168, 127484=>169, 127485=>170, 127486=>171, 127487=>172, 127489=>173, 127490=>174, 127514=>175, 127535=>176, 127538=>177, 127539=>178, 127540=>179, 127541=>180, 127542=>181, 127543=>182, 127544=>183, 127545=>184, 127546=>185, 127568=>186, 127569=>187, 127744=>188, 127745=>189, 127746=>190, 127747=>191, 127748=>192, 127749=>193, 127750=>194, 127751=>195, 127752=>196, 127753=>197, 127754=>198, 127755=>199, 127756=>200, 127757=>201, 127758=>202, 127759=>203, 127760=>204, 127761=>205, 127762=>206, 127763=>207, 127764=>208, 127765=>209, 127766=>210, 127767=>211, 127768=>212, 127769=>213, 127770=>214, 127771=>215, 127772=>216, 127773=>217, 127774=>218, 127775=>219, 127776=>220, 127792=>221, 127793=>222, 127794=>223, 127795=>224, 127796=>225, 127797=>226, 127799=>227, 127800=>228, 127801=>229, 127802=>230, 127803=>231, 127804=>232, 127805=>233, 127806=>234, 127807=>235, 127808=>236, 127809=>237, 127810=>238, 127811=>239, 127812=>240, 127813=>241, 127814=>242, 127815=>243, 127816=>244, 127817=>245, 127818=>246, 127819=>247, 127820=>248, 127821=>249, 127822=>250, 127823=>251, 127824=>252, 127825=>253, 127826=>254, 127827=>255, 127828=>256, 127829=>257, 127830=>258, 127831=>259, 127832=>260, 127833=>261, 127834=>262, 127835=>263, 127836=>264, 127837=>265, 127838=>266, 127839=>267, 127840=>268, 127841=>269, 127842=>270, 127843=>271, 127844=>272, 127845=>273, 127846=>274, 127847=>275, 127848=>276, 127849=>277, 127850=>278, 127851=>279, 127852=>280, 127853=>281, 127854=>282, 127855=>283, 127856=>284, 127857=>285, 127858=>286, 127859=>287, 127860=>288, 127861=>289, 127862=>290, 127863=>291, 127864=>292, 127865=>293, 127866=>294, 127867=>295, 127868=>296, 127872=>297, 127873=>298, 127874=>299, 127875=>300, 127876=>301, 127877=>302, 127878=>303, 127879=>304, 127880=>305, 127881=>306, 127882=>307, 127883=>308, 127884=>309, 127885=>310, 127886=>311, 127887=>312, 127888=>313, 127889=>314, 127890=>315, 127891=>316, 127904=>317, 127905=>318, 127906=>319, 127907=>320, 127908=>321, 127909=>322, 127910=>323, 127911=>324, 127912=>325, 127913=>326, 127914=>327, 127915=>328, 127916=>329, 127917=>330, 127918=>331, 127919=>332, 127920=>333, 127921=>334, 127922=>335, 127923=>336, 127924=>337, 127925=>338, 127926=>339, 127927=>340, 127928=>341,
def download_google_emojis(url_template)
puts "Downloading emojis for google..."
2014-12-22 18:12:26 -06:00
path = "public/images/google"
FileUtils.rm_rf(path) rescue nil
FileUtils.mkdir_p(path) rescue nil
Emoji.all.each do |emoji|
codepoint = emoji["emoji"].codepoints.first
filename = GOOGLE_EMOJIS[codepoint]
next if filename.nil?
puts "#{filename} -> #{emoji["emoji"]}"
url = url_template % filename
data = File.open(url, "rb").read
next if data.nil?
FileUtils.cd(path) do
emoji["aliases"].each do |name|
File.open("#{name}.png", "wb") { |f| f << data }
2015-05-28 21:39:55 -05:00
ImageOptim.new.optimize_image!("#{name}.png")
end
end
end
end