Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
「Goで画像合成!」OGP画像の動的生成 / Dynamic generation of OG...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yuichi Tsunematsu
November 24, 2021
Programming
1.4k
0
Share
「Goで画像合成!」OGP画像の動的生成 / Dynamic generation of OGP images by Golang
[非公式]Go Reject Con 2021 の発表資料です
https://moneyforward.connpass.com/event/228698/
Yuichi Tsunematsu
November 24, 2021
More Decks by Yuichi Tsunematsu
See All by Yuichi Tsunematsu
成功をつなげる プロジェクトマネジメントの探求 / Exploring Project Management to Continuous Success
tunepolo
0
380
組織のスケーリングと持続性 / Scaling and Sustainability
tunepolo
9
10k
信頼される振る舞いを継続しましょう / Keep up the trusted behavior
tunepolo
2
1.3k
アジャイルプラクティスガイドブックを携え、チームで現場を変えていく / Improve your development process with Agile Practices Guidebook
tunepolo
0
300
チームではじめる 「アジャイルプラクティス」 実践の第一歩 / First step to start implementing "Agile Practices" with your team
tunepolo
2
1.7k
アジャイルプラクティスガイドブックの紹介 / introduction of Agile Practice Guidebook
tunepolo
0
1.2k
技術プラクティスの整理に1年半向き合ってわかったこと / What I learned from facing the arrangement of technical practices.
tunepolo
1
2k
「全社でアジャイル!」を広げるために / Expand Agile throughout the Company
tunepolo
1
1.9k
アウトプットが当たり前の文化をつくる / Create a culture where output is the norm.
tunepolo
0
2.8k
Other Decks in Programming
See All in Programming
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.4k
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
140
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
130
さぁV100、メモリをお食べ・・・
nilpe
0
130
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
240
Oxlintのカスタムルールの現況
syumai
5
980
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
340
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
530
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.3k
ReactとSvelteのその先、Ripple-TS / Beyond React and Svelte: Ripple-TS
ssssota
3
2k
Spec-Driven Development with AI-Agents: From High-Level Requirements to Working Software
antonarhipov
2
440
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
130
Information Architects: The Missing Link in Design Systems
soysaucechin
0
960
Designing for Timeless Needs
cassininazir
1
250
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.2k
GitHub's CSS Performance
jonrohan
1033
470k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
270
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
380
The Cult of Friendly URLs
andyhume
79
6.9k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
400
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
240
Chasing Engaging Ingredients in Design
codingconduct
0
210
Transcript
「Goで画像合成!」OGP画像の動的生成 Retty株式会社 常松祐一 2021/11/24
自己紹介 常松祐一 (つねまつ ゆういち) • Engineering Manager •
Software Engineering Coach • Agile Development SNSアカウント • tunepolo : • tune : https://user.retty.me/3946697/ 今日は上記画像を生成するサービスを サマーインターンで開発してもらった話です
OGP画像とは • SNSシェア時に表示されるサムネイル画像のこと ◦ “Open Graph Protocol”で定義されており、HTMLにメタタグを入れるこ とで使うことができる。
ページ種別によってOGP画像の仕様は異なる 【店舗紹介ページ】 画像1枚をサイズ調整 【ユーザページ】 アイコンと補足情報から合成 アイコン 補足情報 左右に 余白 上下を
カット
画像合成のアプローチ 1. 画像ライブラリを自前で操作 ◦ Good: 必要最小限の処理で済む ◦ Bad: 文字レイアウトが困難 2.
HTMLを動的生成し、キャプチャする ◦ Good: 文字が多いレイアウトが作りやすい。 ◦ Bad: HTMLレンダリングを挟むため重い インターン生 + メンターで議論してもらった結果、2を選択 1, 2共にtimakinさんのnoteにまとまっています Goでheadless browserを用いた 動的画像生成
• CleanArchitecture • echo(web framework) • wire(DI) • httptest +
chromedp • imageorient サービス構成 OGPサービス ユーザサービス など HTTPS 1. データ取得 2. HTML生成 3. レンダリング &キャプチャ
合成画像をキャプチャする箇所のコード なんと シンプル!
苦労したところ - アイコンフォントをどう持たせるか • Web/アプリでも使われるデータのため、共通管理したい • OGPサーバー内部でHTMLをレンダリングする際にアイコンフォントをどう やって配信する? ◦ webpack
+ webfonts-loaderでビルドした成果物を静的に抱き込む形 として対処 ◦ もっといい解決策があれば知りたい
HTMLテンプレート 合成用ロゴ デフォルトOGP画像 go:embedによるファイル埋め込みは便利
まとめ • HTMLを動的生成する画像合成は実用的 ◦ 画像生成までの流れが整理できていると、パターンを増や すことは簡単 ◦ パフォーマンス(処理時間・CPU・メモリ)も問題になることは なかった •
3週間で0から開発し、サービス投入まで実現してくれたイン ターン生の皆様に敬意と感謝 Photo by Max Delsid on Unsplash
エンジニア募集中! 11 ITで新たな食体験を提供していく「 Retty」のプロダ クト開発に携わるバックエンドエンジニアを募集し ます。 マイクロサービス化、新規事業など一緒に Goで開 発しませんか。 Go
Conferenceの発表で盛り込めなかった話や 残念ながら採択されなかったプロポーザルの話、 Go Conferenceに参加してみての感想戦、 Retty におけるGoでのプロダクト開発など、ざっくばらん にお話いたします!