【问题标题】:High quality book covers using Google Books API使用 Google Books API 的高质量书籍封面
【发布时间】:2021-08-29 00:54:36
【问题描述】:

According to the Google Books API documentation 每个卷产生 6 个不同的图像链接(smallThumbnail、thumbnail、small、medium、large、extraLarge)。

不幸的是,对于我尝试过的所有查询(并且我尝试过很多次),只返回了 smallThumbnailthumbnail。 (Example query)

另外,这两张图片除了很小之外,右下角还有这个小假狗耳朵

他们是否弃用了高质量的图片链接?还有其他方法可以获取这些图像吗?我尝试过的其他 API 要么已弃用(Goodreads),要么不太广泛(开放库)

【问题讨论】:

    标签: google-books-api


    【解决方案1】:

    我也有同样的问题。搜索查询仅产生 imageLinks 的 smallThumbnail 和 thumbnail 键。如果您直接查询卷(如this),那么您将获得 imageLinks 的所有选项。

    但这不会 100% 解决您的问题。对于某些图书,小/中/大链接指向图书的第一页,而不是实际的封面。

    【讨论】:

      【解决方案2】:

      您可能无法始终获得高分辨率图像。此外,对于某些图书搜索结果,您可能根本看不到任何图像。

      我正在做一个类似的项目,我不得不手动检查我在回复中得到的每张图片的分辨率,我只选择了“好”的图片。 这是我必须做的:

              let newArr = [];
              let lowResImage = 0;
              let dataWithoutImage = 0;
              let highResImage = 0;
      genreResults?.forEach((book, index) => {
      
              if (book?.volumeInfo?.imageLinks?.smallThumbnail) {//the current book has an image
      
                  mypromise(book.volumeInfo.imageLinks.smallThumbnail).then((res) => {
                      ++highResImage;
                      newArr.push(book)
                  }).catch(error => {
                      ++lowResImage;
                  }).finally(() => {
                      if (dataWithoutImage + highResImage + lowResImage === genreResults.length) {
                          console.log("---------data populated----------");
                          console.log("highResolutionImages", highResImage);
                          console.log("low resolution images:", lowResImage);
                          console.log("booksWithoutImages", dataWithoutImage);
                          console.log("genreResults size", genreResults.length)
                          setBooks(newArr)
                      }
                  });
      
              }
              else //this book does not contain an image
                  ++dataWithoutImage
      
          })
      

      检查分辨率的函数如下所示:

      let mypromise = function checkImageResolution(url) {
          return new Promise((resolve, reject) => {
              var img = new Image();
              img.src = url;
              img.onload = function () {
                  console.log("image dimensions", this.width, this.height);
                  if (this.width < 125 || this.height < 100) //if either of these is true, reject the image
                      reject("low quality image");
                  else
                      resolve("high quality ,let's have this one");
              }
          });
      }
      

      【讨论】:

        【解决方案3】:

        替换以下内容:

        thumbnail=thumbnail.replaceAll("1","10");
        

        但它仅适用于某些书籍,而对于其余书籍,它只会加载书籍的第一页。

        【讨论】:

        • 欢迎来到 Stack Overflow!请花点时间阅读editing help 中的help center。 Stack Overflow 上的格式与其他网站不同。
        猜你喜欢
        • 1970-01-01
        • 2013-01-03
        • 1970-01-01
        • 2014-12-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-12-18
        • 2021-12-26
        相关资源
        最近更新 更多