如何在Google自定义搜索中指定图像类型 [英] How to specify Image type in Google Custom Search

查看:206
本文介绍了如何在Google自定义搜索中指定图像类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google自定义搜索来获取具有某些条件的图片。

我发起HTTP从Java应用程序获取请求以调用Google自定义搜索API
(请注意我使用javascript或css,我开发网站。)



我能够获取图像,程序正在运行。该应用程序带来了 Jpg 扩展名的图片。



我想:




  • ONLY 的图片 png 扩展程序 AND 透明背景。



我试图在查询字符串中指定 filetype 像这样的请求网址

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

但结果仍然在 jpg ,Google自定义搜索只带来一两个结果。



备注




  • 我将Google自定义搜索(从其控制面板)配置为全部搜索网络,我不限制它搜索某些网站。


  • 我配置Google自定义搜索以启用图片搜索拱形(也来自控制面板)像这样







  • 我还将搜索结果配置为ImageResult(来自搜索功能 - > 高级页面)如下图所示





我还创建了来自谷歌文档的这个代码示例限制了图像的类型,但它们似乎在javascripts(不是在java中),根本不适合我。



更新
我找到了一个搜索解决方案对于 png 文件,解决方案是在查询本身中提供 filetype:png ,而不是将此值指定为查询字符串到Google自定义搜索。结果合理且可以接受。



更新
我也试过 tbs 查询字符串参数,在Google图片搜索中使用,如果我们想要获取透明图片,则其工作如下

  TBS = IC:反式安培; 

这仅适用于Google图片搜索,但它不适用于Google自定义搜索。即使我使用 hq 参数进行Google自定义搜索,只需将参数添加到网址即可添加 tbs 参数。



但我仍然无法通过Google自定义搜索来带来仅具有透明背景的图片。



更新



如果有办法使用Bing搜索实现相同的目标(带来透明背景的图像) API,我也会接受答案。
我也尝试了Bing Search API,它也有效,但同样的问题出现了,没有办法指明我需要一个透明背景的图像。



<根据 更新
nofollow noreferrer>此讨论

Google弃用的搜索API中有未记录的参数,它带有透明图像,如下所示

  imgc = trans 

这适用于旧的已弃用的Google搜索api,但它不适用于新的API,也不适用于BING api。



UPDATE
For Bing Search API我尝试添加此查询参数,该参数将BING图像搜索中的透明背景(在网站中不在API中)附加到URL

  qft = + filterui:photo-transparent 

虽然这适用于Normal BING搜索,但它不适用于BING Search API。

解决方案

如何将透明放在查询字符串的末尾?它对我有用:& q =< brand> + logo + transparent
和filetype & filetype = png


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.

解决方案

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

这篇关于如何在Google自定义搜索中指定图像类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆