更改 Twitch 图片的尺寸 API
Change dimensions of images from Twitch API
我正在向 Twitch API 请求获取热门游戏列表并显示他们的封面图,但只有在我更改 width
和 height
提供的值 link。我如何在 ejs 中更改这些值,或者我应该在提供上下文之前更改这些值?
<% data.forEach(game => { %>
<img src= <%= game.box_art_url %> alt="">
<%})%>
示例API响应
{
"id": "21779",
"name": "League of Legends",
"box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-{width}x{height}.jpg"
}
在 ejs
中用您自己的尺寸替换 {width}
和 {height}
- 例如:
<% data.forEach(game => { %>
<img src= <%= game.box_art_url.replace('{width}', '138').replace('{height}', '190') %> alt="">
<%})%>
这将输出:
<img src="https://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-138x190.jpg" alt="">
我正在向 Twitch API 请求获取热门游戏列表并显示他们的封面图,但只有在我更改 width
和 height
提供的值 link。我如何在 ejs 中更改这些值,或者我应该在提供上下文之前更改这些值?
<% data.forEach(game => { %>
<img src= <%= game.box_art_url %> alt="">
<%})%>
示例API响应
{
"id": "21779",
"name": "League of Legends",
"box_art_url": "https://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-{width}x{height}.jpg"
}
在 ejs
中用您自己的尺寸替换 {width}
和 {height}
- 例如:
<% data.forEach(game => { %>
<img src= <%= game.box_art_url.replace('{width}', '138').replace('{height}', '190') %> alt="">
<%})%>
这将输出:
<img src="https://static-cdn.jtvnw.net/ttv-boxart/League%20of%20Legends-138x190.jpg" alt="">