How to specify Image type in Google Custom Search
Asked Answered
L

3

10

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

enter image description here

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

enter image description here

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.

Limousine answered 2/12, 2015 at 7:5 Comment(0)
P
3

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.

Philana answered 4/12, 2015 at 10:2 Comment(2)
I tried this before it works for the google images search. but it did not works for the Google Custom Search, I am sorry because i did not said that before in my questionAuberon
I updated my question to include note about this feature. Thanks you any way for your time.Auberon
U
1

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

Underprop answered 11/12, 2015 at 2:57 Comment(3)
do you have reference to for this??Auberon
Well, it's hard to find a reference for something that do not exists ;) The official documentation does not mention the transparent search request criteria onedrive.live.com/…Underprop
It is now possible to search for transparent images only learn.microsoft.com/en-us/azure/cognitive-services/…Retrieve
B
1

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

Bandur answered 15/11, 2017 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.