2017-04-12 61 views
0

高分辨率圖像我有一個簡單的腳本來從版(Subreddit)獲取圖像:拉從reddit的API

唯一的問題是,它的拉動低分辨率大拇指代替高分辨率圖像。

fetch('https://www.reddit.com/r/RoomPorn.json') 
    .then(res => res.json()) 
    .then(res => res.data.children) 
    .then(res => res.map(post => ({ 
    author: post.data.author, 
    link: post.data.url, 
    img: post.data.thumbnail, 
}))) 

.then(res => res.map(render)) 
.then(res => console.log(res)) 

const app = document.querySelector('#app'); 

const render = post => { 
const node = document.createElement('div'); 
node.innerHTML = ` 
    <a href="${post.link}"> 
    <img src="${post.img}"/> 
    </a>`; 
app.appendChild(node); 

}

是否有可能拉高分辨率呢?

謝謝您的時間,

  • ķ

回答

1

嘗試:

fetch('https://www.reddit.com/r/RoomPorn.json') 
    .then(res => res.json()) 
    .then(res => res.data.children) 
    .then(res => res.map(post => ({ 
    author: post.data.author, 
    link: post.data.url, 
    img: post.data.preview.images[0].source.url, 
}))) 

BTW post.data.url應該從原始來源的高分辨率圖像鏈接。

+0

非常感謝您的回覆。 我試過你的腳本: https://jsfiddle.net/7f0zyp3z/3/ 但它未能獲取,任何想法? –

+0

@ kathrynm你忘了在這個jsfiddle中調用你的渲染方法。試試:https://jsfiddle.net/7f0zyp3z/5/ – xDreamCoding

+1

這正是我需要的,謝謝 –