Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image URL #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions fake/examples/fakers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -389,6 +407,7 @@ fn main() {
phone_number_faker();
filesystem_faker();
currency_faker();
image_faker();

#[cfg(feature = "http")]
http_faker();
Expand Down
28 changes: 28 additions & 0 deletions fake/src/faker/impls/image.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::faker::image::raw::*;
use crate::locales::Data;
use crate::{Dummy};
use rand::Rng;

impl<L: Data> Dummy<Unsplash<L>> for String {
fn dummy_with_rng<R: Rng + ?Sized>(_: &Unsplash<L>, rng: &mut R) -> Self {
format!("https://picsum.photos/{:?}", rng.gen_range(100, 1080))
}
}

impl<L: Data> Dummy<UnsplashWithSize<L>> for String {
fn dummy_with_rng<R: Rng + ?Sized>(c: &UnsplashWithSize<L>, _: &mut R) -> Self {
format!("https://picsum.photos/{:?}/{:?}", c.1, c.2)
}
}

impl<L: Data> Dummy<UnsplashGrayscale<L>> for String {
fn dummy_with_rng<R: Rng + ?Sized>(c: &UnsplashGrayscale<L>, _: &mut R) -> Self {
format!("https://picsum.photos/{:?}/{:?}?grayscale", c.1, c.2)
}
}

impl<L: Data> Dummy<UnsplashBlur<L>> for String {
fn dummy_with_rng<R: Rng + ?Sized>(c: &UnsplashBlur<L>, _: &mut R) -> Self {
format!("https://picsum.photos/{:?}/{:?}?blur={:?}", c.1, c.2, c.3)
}
}
1 change: 1 addition & 0 deletions fake/src/faker/impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod currency;
mod filesystem;
#[cfg(feature = "http")]
mod http;
mod image;
mod internet;
mod job;
mod lorem;
Expand Down
9 changes: 9 additions & 0 deletions fake/src/faker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}