How to specify Image type in Google Custom Search

2019-04-22 13:37发布

问题:

I am using Google Custom Search to get images with some criteria.
I am initiating HTTP Get requests from java application to call the Google Custom Search API
(Please note I am NOT using javascript or css and I am NOT developing web site).

I am able to get the images, and the program is working. the application brings images which has Jpg extension.

I want to :

  • bring ONLY the images which has png extension AND has transparent background.

I tried to specify the filetype in the query string of the request URL like this

https://www.googleapis.com/customsearch/v1?q=cars&filetype=png&cx=[myinformatino]&searchType=image&rights=cc_publicdomain&num=10&key=[myKey]

but the result is really still in jpg and the Google Custom search brings only one or two result.

Notes

  • I configured the Google Custom Search (from its Control panel) to search all the web, I am not restricting it to search some sites.

  • I configured the Google Custom Search to enable the Image Searching (also from Control panel) like this

  • I also configured the search result to the ImageResult (from the Search Features -> Advanced page) as the following picture

I also founded this code examples from google documentation which restrict the type of the Image but they seems to be in javascripts (NOT in java) which not suitable for me at all.

UPDATE I found a solution for searching for png files, the solution was by providing the filetype:png in the query itself instead of specify this value as query string to the Google Custom Search. and The result is reasonable and acceptable.

UPDATE I also tried the tbs query string parameter which is used in the Google Image search which worked as the following if we want to get the transparent images

?tbs=ic:trans&

this works only for Google Image Search, But it did not work in the Google Custom Search. Even when I used the hq parameter for the Google Custom Search which just add the parameter as it is to the url to add the tbs parameter.

BUT I Still can not fore the Google Custom Search to bring the Images which has the transparent background only.

UPDATE

if there is a way to achieve the same goal (bringing the images with transparent background) using Bing Search API, I will also accept the answer. I tried also the Bing Search API, It worked also, but the same problem appeared, there is no way to specify that I need a images with transparent background.

UPDATE according to this discussion there is undocumented parameter in the Google deprecated search api which do bring the transparent images, which as the following

imgc=trans

this is working for the old deprecated google search api, but it does not work for the new API and it does not worked also for the BING api.

UPDATE For Bing Search API I tried to add this query parameter which speicyf the transparent background in the BING image search (in the website not in the API) to the URL

qft=+filterui:photo-transparent

although this is working for the Normal BING search, it did not work for the BING Search API.

回答1:

Looking the url of image search, I found that the parameter is tbs.

For exemple:

transparent image : ...&tbs=ic:trans&....
gray image: ...&tbs=ic:gray&...
specific color (Eg: orange): ...&tbs=ic:specific,isc:orange&...

M.



回答2:

for the Bing question, this feature is not implemented in the API yet.



回答3:

How about putting "transparent" at the end of query string? It worked for me: &q="<brand>+logo+transparent" and for filetype &filetype=png