I’m new to react native but I’ve been using JavaScript for a while. I’m trying to get the aspect ratio so my images look nice using Image.getSize, but I keep getting the following warning:
Failed to get size for image: https://books.google.com/books/content?id=NYMD0AEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api
Here’s my code where I’m implementing getSize:
const handleIsbnSearch = async () => {
const books = await isbnSearch(isbn);
if (books.error) {
return setBookSearch([]);
}
let bookInfo = [];
for (let b in books) {
const volInfo = books[b].volumeInfo
const {width, height} = await Image.getSize(volInfo.imageLinks.thumbnail);
const aspectRatio = width/height;
console.log(aspectRatio);
bookInfo.push({
title: volInfo.title,
subtitle: volInfo.subtitle,
authors: volInfo.authors,
publisher: volInfo.publisher,
publishedDate: volInfo.publishedDate,
description: volInfo.description,
categories: volInfo.categories,
thumbnail: volInfo.imageLinks.thumbnail,
aspectRatio: aspectRatio
})
}
setBookSearch(bookInfo);
}
I know the uri is correct because I’m able to load the photo in the app, but for some reason, it can’t get the Image size.
Any help would be appreciated!
I’ve tried replacing “http” with “https”, but that didn’t seem to make a difference. Initially, I was not using await
when calling Image.getSize()
, and had to change from a forEach
loop to a for
loop. I’ve also tried calling the method in other places in the code and have tried different uri
s.
Warren Tefft is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.