用于方形图像的Google自定义搜索API [英] Google Custom Search API for square images

查看:112
本文介绍了用于方形图像的Google自定义搜索API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来指定由Google自定义搜索API返回的图像具有正方形格式。



我试过tbs = iar: (因为我读过使用自定义搜索API(REST JSON)搜索方形图片),但它不起作用。



您有想法吗?

解决方案

问题在于 tbs 查询参数仅适用于常规图片搜索谷歌。例如,如果您想搜索具有正方形宽高比的猫图片,可以这样搜索:

http://images.google.com/?q=cat&tbs=iar:s



但自定义搜索API使用完全不同的一组参数。 REST文档中显示了支持的参数的完整列表。

一些tbs查询确实有等价的。例如:


  • tbs = ic:grey 转换为 imgColorType = grey

  • tbs = isz:m 转换为 imgSize =中等

  • tbs = itp:clipart 转换为 imgType = clipart



但遗憾的是, iar 宽高比滤波器。我曾尝试猜测一些查询(如 imgAspectRatio = square ),以防有无证参数,但没有任何运气。



我可以建议的最佳选择是使用 imgSize = icon 。这往往会返回具有正方形宽高比的图像,但带有不幸的副作用,图像也往往很小(我看到的最大尺寸是256x256)。根据你的需要,这可能已经足够了。



如果这对你没有特别的用处,我表示歉意。我不只是想在这个问题上获得赏金,所以请随意不要投这个答案。我只是想让你知道我发现了什么,以防它有一些帮助。


I'm looking for a way to specify that the images returned by the Google Custom Search API have a square format.

I've tried tbs=iar:s (because I've read Using the Custom Search API (REST JSON) to search for square images), but it doesn't work.

Have you an idea please ?

解决方案

The problem is that tbs query parameter only applies to a regular image search on Google. For example, if you wanted to search for cat pictures with a square aspect ratio, you could do a search like this:

http://images.google.com/?q=cat&tbs=iar:s

But the Custom Search API uses a completely different set of parameters. The full list of supported parameters is shown in the REST documentation.

Some of the tbs queries do have equivalents. For example:

  • tbs=ic:gray translates to imgColorType=gray
  • tbs=isz:m translates to imgSize=medium
  • tbs=itp:clipart translates to imgType=clipart

But sadly there appears to be no equivalent for the iar aspect ratio filter. I tried guessing a few queries (things like imgAspectRatio=square) in case there was an undocumented parameter, but didn't have any luck with that.

The best alternative I could suggest is using imgSize=icon. This tends to return images that have a square aspect ratio, but with the unfortunate side effect that the images also tend to be rather small (the largest size I've seen returned is 256x256). Depending on your needs though, this may be good enough.

I apologise if this isn't particularly useful to you. I'm not just trying to grab the bounty on this question, so feel free not to vote this answer up. I just wanted to let you know what I had found in case it was of some help.

这篇关于用于方形图像的Google自定义搜索API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆