Documentation ¶
Overview ¶
A package designed to search Google Images based on the input query and arguments. Due to the limitations of using only a single request to fetch images, only a max of about 100 images can be found per request. If you need to find more than 100, one of the many packages using simulated browsers may work better. These images may be protected under copyright, and you shouldn't do anything punishable with them, like using them for commercial use.
Index ¶
- Variables
- func Download(query string, limit int, dir string, arguments ...string) (paths []string, missing int, err error)
- func DownloadImage(url, dir, name string) (imgpath string, err error)
- func IsUnpackErr(err error) bool
- func Urls(query string, limit int, arguments ...string) (urls []string, err error)
- type Image
Constants ¶
This section is empty.
Variables ¶
var ( Color = struct { Red, Orange, Yellow, Green, Teal, Blue, Purple, Pink, White, Gray, Black, Brown string }{Red: "isc:red", Orange: "isc:orange", Yellow: "isc:yellow", Green: "isc:green", Teal: "isc:teel", Blue: "isc:blue", Purple: "isc:purple", Pink: "isc:pink", White: "isc:white", Gray: "isc:gray", Black: "isc:black", Brown: "isc:brown"} ColorType = struct { Color, Grayscale, Transparent string }{Color: "ic:full", Grayscale: "ic:gray", Transparent: "ic:trans"} License = struct { CreativeCommons, Other string }{CreativeCommons: "il:cl", Other: "il:ol"} Type = struct { Face, Photo, Clipart, Lineart, Animated string }{Face: "itp:face", Photo: "itp:photo", Clipart: "itp:clipart", Lineart: "itp:lineart", Animated: "itp:animated"} Time = struct { PastDay, PastWeek, PastMonth, PastYear string }{PastDay: "qdr:d", PastWeek: "qdr:w", PastMonth: "qdr:m", PastYear: "qdr:y"} AspectRatio = struct { Tall, Square, Wide, Panoramic string }{Tall: "iar:t", Square: "iar:s", Wide: "iar:w", Panoramic: "iar:xw"} Format = struct { Jpg, Gif, Png, Bmp, Svg, Webp, Ico, Raw string }{Jpg: "ift:jpg", Gif: "ift:gif", Png: "ift:png", Bmp: "ift:bmp", Svg: "ift:svg", Webp: "webp", Ico: "ift:ico", Raw: "ift:craw"} )
These variables are all of the possible arguments that can be passed into Images, Download, and Urls. These are used by passing imagesearch.{Argument}.{Option} into the arguments parameter. For example:
urls, err := imagesearch.Urls("example", 0, imagesearch.Color.Red, imagesearch.License.CreativeCommons)
Functions ¶
func Download ¶
func Download(query string, limit int, dir string, arguments ...string) (paths []string, missing int, err error)
Searches for the given query along with the given argumetnts and downloads the images into the given directory. The amount of images does not exceed the limit unless the limit is 0, in which case it will download all images found. Returns a slice of the absolute paths of all downloaded images, along with the number of missing images.
The number of missing images is the difference between the limit and the actual number of images downloaded. This is only non-zero when the limit is higher than the number of downloadable images found.
func DownloadImage ¶
Given the url of the image, the directory to download to, and the name of the file *without extension*, this will find the type of image and download it to the given directory. Warning: This will overwrite any image file with the same name, if the extension matches, so make sure to keep the name unique. You can check if a file with the name already exists with the following code:
import ( "path" "path/filepath" ) func exists(dir, name string) bool { pat := path.Join(dir, name) + ".*" matches, _ := filepath.Glob(pat) return len(matches) > 0 }
func IsUnpackErr ¶
Checks if an error is an unpacking error. An unpacking error is generally thrown when Google changes their JSON structure, or on certain internet connections, when the specific header does not work. If you believe Google changed their JSON structure, please submit a bug report at https://github.com/Jibble330/imagesearch/issues, and I will try to fix this asap.
Types ¶
type Image ¶
type Image struct { // Image URL Url string `json:"url"` // URL the image was found at Source string `json:"source"` // Base of the source URL Base string `json:"base"` }
Contains information about an image including the url of the image, the url of the source, and the website it came from. Example:
Image { Url: "www.example.com/static/image.png" Source: "www.example.com/article" Base: "example.com" }