首页 > 解决方案 > React Native 调整图片 url

问题描述

我从 node.js 服务器获取图像 url 并将它们显示在我的应用程序中。目前,我的代码如下所示:

<Image source={{ uri: `https:${game.url}` }} style={[styles.photo, { width: game.width / 2, height: game.height / 1.4 }]} />

服务器返回的 URL 如下所示:

'//images.igdb.com/igdb/image/upload/t_thumb/co2dc0.jpg'

但是,尺寸和质量非常小。在我的代码中,我需要根据 api 文档将“t.thumb”参数替换为更大的参数


Break down:

https://images.igdb.com/igdb/image/upload/t_{size}/{hash}.jpg

size is one of the interchangeable size types listed below. hash is the id of the image. The image sizes are all maximum size but by appending _2x to any size, you can get retina (DPR 2.0) sizes (cover_small_2x).

Name                 Size       Extra
cover_small         90 x 128    Fit
screenshot_med      569 x 320   Lfill, Center gravity
cover_big           264 x 374   Fit
logo_med            284 x 160   Fit
screenshot_big      889 x 500   Lfill, Center gravity
screenshot_huge     1280 x 720  Lfill, Center gravity
thumb   90 x 90     Thumb, Center gravity
micro   35 x 35     Thumb, Center gravity
720p    1280 x 720  Fit, Center gravity
1080p   1920 x 1080 Fit, Center gravity

如何用我提供的代码中的其他内容替换 t_thumb?

标签: react-nativeapi

解决方案


推荐阅读