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 ?
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.
Google Reverse Image API allows to get results for image search https://images.google.com .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With