Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Custom Search API for square images

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 ?

like image 759
Arnaud Avatar asked May 27 '13 10:05

Arnaud


People also ask

How do I search Google for square images?

Here's how. Go to images.google.com and enter the search terms as before. Then append imagesize:WIDTHxHEIGHT to your query and hit Enter. Google Images will remove the operator from the query but the results will only display images that match the specified size.

Does Google have an API for image search?

Google Reverse Image API allows to get results for image search https://images.google.com .

How do I use Google Custom Search API?

Custom Search JSON API requires the use of an API key. An API key is a way to identify your client to Google. After you have an API key, your application can append the query parameter key=yourAPIKey to all request URLs. The API key is safe for embedding in URLs, it doesn't need any encoding.


1 Answers

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.

like image 80
James Holderness Avatar answered Sep 18 '22 17:09

James Holderness