Node.jsでGravatarの画像を取得するメモ
3413 ワード
Gravatarの画像をNode.jsから取得します。 事前に利用するメールアドレスでgravatarに登録してある前提です。
- step1: emailハッシュを作成
- step2: URLを作成
step1: email ハッシュ
md5でemailハッシュを作成します。外部依存モジュール使わないで出来ますね。
'use strict'
const crypto = require('crypto')
//md5ハッシュを作る関数を作成
const md5hex = str => crypto.createHash('md5').update(str, 'binary').digest('hex')
const mail = '[email protected]' //ここにメールアドレス
console.log(`email hash: ` + md5hex(mail));
//email hash: ca0740a1455580936ff1bdc634fb8e2f
step2: URLを作成
https://www.gravatar.com/avatar/ + ハッシュ
という形式でアクセスするとアイコンが取得できます。
例: https://www.gravatar.com/avatar/dae1d4cc4599a65a5da6e1a1f9d96f05
おまけ ?s=xxxでサイズ変更
- s=10
https://www.gravatar.com/avatar/dae1d4cc4599a65a5da6e1a1f9d96f05?s=10
- s=50
https://www.gravatar.com/avatar/dae1d4cc4599a65a5da6e1a1f9d96f05?s=50
- s=100
https://www.gravatar.com/avatar/dae1d4cc4599a65a5da6e1a1f9d96f05?s=100
- s=200
https://www.gravatar.com/avatar/dae1d4cc4599a65a5da6e1a1f9d96f05?s=200
Author And Source
この問題について(Node.jsでGravatarの画像を取得するメモ), 我々は、より多くの情報をここで見つけました https://qiita.com/n0bisuke/items/588105ea6a4b2488816b著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .