Google Custom Search API for square images

那年仲夏 提交于 2019-12-21 09:17:59

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/16770726/google-custom-search-api-for-square-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!