diff --git a/README.md b/README.md index 5001a9f..1762a15 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,14 @@ FileExtension(); DirPath(); ``` +## Image +```rust +Unsplash(); +UnsplashWithSize(width: u16, height: u16); +UnsplashGrayscale(width: u16, height: u16); +UnsplashBlur(width: u16, height: u16, blur: u8); +``` + # LICENSE This project is licensed under either of diff --git a/fake/examples/fakers.rs b/fake/examples/fakers.rs index 89accbf..bdf781f 100644 --- a/fake/examples/fakers.rs +++ b/fake/examples/fakers.rs @@ -377,6 +377,24 @@ fn currency_faker() { println!("{:?}", val); } +fn image_faker() { + use fake::faker::image::raw::*; + + let val: String = Unsplash(EN).fake(); + println!("{:?}", val); + + // width: pixels, height: pixels + let val: String = UnsplashWithSize(EN, 600, 800).fake(); + println!("{:?}", val); + + let val: String = UnsplashGrayscale(EN, 600, 800).fake(); + println!("{:?}", val); + + // blur: [1-10] + let val: String = UnsplashBlur(EN, 600, 800, 5).fake(); + println!("{:?}", val); +} + fn main() { lorem_faker(); name_faker(); @@ -389,6 +407,7 @@ fn main() { phone_number_faker(); filesystem_faker(); currency_faker(); + image_faker(); #[cfg(feature = "http")] http_faker(); diff --git a/fake/src/faker/impls/image.rs b/fake/src/faker/impls/image.rs new file mode 100644 index 0000000..46ec122 --- /dev/null +++ b/fake/src/faker/impls/image.rs @@ -0,0 +1,28 @@ +use crate::faker::image::raw::*; +use crate::locales::Data; +use crate::{Dummy}; +use rand::Rng; + +impl Dummy> for String { + fn dummy_with_rng(_: &Unsplash, rng: &mut R) -> Self { + format!("https://picsum.photos/{:?}", rng.gen_range(100, 1080)) + } +} + +impl Dummy> for String { + fn dummy_with_rng(c: &UnsplashWithSize, _: &mut R) -> Self { + format!("https://picsum.photos/{:?}/{:?}", c.1, c.2) + } +} + +impl Dummy> for String { + fn dummy_with_rng(c: &UnsplashGrayscale, _: &mut R) -> Self { + format!("https://picsum.photos/{:?}/{:?}?grayscale", c.1, c.2) + } +} + +impl Dummy> for String { + fn dummy_with_rng(c: &UnsplashBlur, _: &mut R) -> Self { + format!("https://picsum.photos/{:?}/{:?}?blur={:?}", c.1, c.2, c.3) + } +} \ No newline at end of file diff --git a/fake/src/faker/impls/mod.rs b/fake/src/faker/impls/mod.rs index 1a9589e..d96f795 100644 --- a/fake/src/faker/impls/mod.rs +++ b/fake/src/faker/impls/mod.rs @@ -7,6 +7,7 @@ mod currency; mod filesystem; #[cfg(feature = "http")] mod http; +mod image; mod internet; mod job; mod lorem; diff --git a/fake/src/faker/mod.rs b/fake/src/faker/mod.rs index 4f88fc8..e375725 100644 --- a/fake/src/faker/mod.rs +++ b/fake/src/faker/mod.rs @@ -185,3 +185,12 @@ pub mod currency { CurrencySymbol(); } } + +pub mod image { + def_fakers! { + Unsplash(); + UnsplashWithSize(width: u16, height: u16); + UnsplashGrayscale(width: u16, height: u16); + UnsplashBlur(width: u16, height: u16, blur: u8); + } +} \ No newline at end of file