Expand description
A crate designed to search Google Images based on provided 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. These images may be protected under copyright, and you shouldn’t do anything punishable with them, like using them for commercial use.
§Examples
Using the asynchronous API requires some sort of async runtime, usually tokio
, which can be added to your Cargo.toml
like so:
[dependencies]
image_search = "0.4"
tokio = { version = "1", features = ["full"] }
It can be used like this:
extern crate tokio;
extern crate image_search;
use std::path::PathBuf;
use image_search::{Arguments, urls, search, download};
#[tokio::main]
async fn main() -> Result<(), image_search::Error> {
let args = Arguments::new("example", 10)
.color(image_search::Color::Gray)
.directory(PathBuf::new("downloads")); // Only affects the download function
// Returns the urls of the search results
let _image_urls = urls(args.clone()).await?;
// Returns the search results as Image structs
let _images = search(args.clone()).await?;
// Downloads the search results and returns the paths to the files
let _paths = download(args).await?;
Ok(())
}
§Blocking
There is an optional “blocking” API that can be enabled:
[dependencies]
image_search = { version = "0.4", features = ["blocking"] }
This is called like so:
extern crate image_search;
use std::path::PathBuf;
use image_search::{Arguments, blocking::{urls, search, download}};
fn main() -> Result<(), image_search::Error> {
let args = Arguments::new("example", 10)
.color(image_search::Color::Gray)
.directory(PathBuf::from("downloads")); // Only affects the download function
let _image_urls = urls(args.clone())?;
let _images = search(args.clone())?;
let _paths = download(args)?;
Ok(())
}
Structs§
- Arguments
- Used to construct the arguments for searching and downloading images.
- Image
- Contains info about an image including the original url, the dimensions of the image (x, y), the url of the thumbnail, and the name of the source.
Enums§
Functions§
- download
- Search for images based on the provided
Arguments
and downloads them to the path specified in thedirectory
field inArguments
, or the “images” folder if none is provided. - search
- Search for images based on the provided arguments and return images up to the provided limit.
- urls
- Search for images based on the provided arguments and return the urls of the images