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

refactor(image)!: randomize defaults #2472

Merged
merged 18 commits into from
Feb 11, 2024
Merged

refactor(image)!: randomize defaults #2472

merged 18 commits into from
Feb 11, 2024

Conversation

olrtg
Copy link
Contributor

@olrtg olrtg commented Oct 12, 2023

Removes hard-coded defaults and randomizes them. Did this to all methods in the image module but didn't touch the deprecated ones.

Fixes #2314.

@olrtg olrtg requested a review from a team as a code owner October 12, 2023 16:05
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
@ST-DDT ST-DDT added c: feature Request for new feature p: 1-normal Nothing urgent breaking change Cannot be merged when next version is not a major release m: image Something is referring to the image module do NOT merge yet Do not merge this PR into the target branch yet labels Oct 12, 2023
@ST-DDT ST-DDT added this to the v9.0 milestone Oct 12, 2023
@codecov
Copy link

codecov bot commented Oct 12, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (50897d9) 99.55% compared to head (00e36ce) 99.55%.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #2472   +/-   ##
=======================================
  Coverage   99.55%   99.55%           
=======================================
  Files        2820     2820           
  Lines      251738   251751   +13     
  Branches     1165     1167    +2     
=======================================
+ Hits       250607   250634   +27     
+ Misses       1102     1088   -14     
  Partials       29       29           
Files Coverage Δ
src/modules/image/index.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

@olrtg
Copy link
Contributor Author

olrtg commented Oct 12, 2023

Done with the comments! Lunch time for me so please let me know if there's anything left to do on my side so I can work on that later. 🤘🏽

src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
We are allowing the zero value to simplify the default value
src/modules/image/index.ts Outdated Show resolved Hide resolved
src/modules/image/index.ts Outdated Show resolved Hide resolved
ST-DDT
ST-DDT previously approved these changes Oct 14, 2023
Copy link
Member

@ST-DDT ST-DDT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Please note that it still wont be merged because it is schedulled for v9.

@olrtg
Copy link
Contributor Author

olrtg commented Oct 14, 2023

Thank you so much! a pleasure working with you 🤘🏽

Copy link
Contributor

@suyashgulati suyashgulati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Copy link
Contributor

@matthewmayer matthewmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While preparing some draft documentation for the breaking change, i found a problem, you can't prevent grey/blurred images when using faker.image.url()

faker.image.url() picks from faker.image.urlLoremFlickr() and faker.image.urlPicsumPhotos() at random. But faker.image.urlPicsumPhotos() now randomly adds blur and grayscale parameters. If you don't want that you can turn it off using for example

faker.image.urlPicsumPhotos({width:640, height:480, blur:0, grayscale:false})

But faker.image.url doesn't support the blur and grayscale parameters, so

faker.image.url({width:640, height:480, blur:0, grayscale:false}) still gives you blurry or greyscale pics on the 50% of picsum photos.

Perhaps blur:0 and grayscale:false should be passed to urlPicsumPhotos() when called by url()

@olrtg olrtg dismissed stale reviews from xDivisionByZerox and ST-DDT via 3e059e7 January 17, 2024 21:20
@olrtg
Copy link
Contributor Author

olrtg commented Jan 17, 2024

@matthewmayer From what I saw in the test snapshots in the latest commit, that should do the trick, but I don't really know how to test this easily or how you test this (will be good to know if you don't mind sharing it).

Let me know if there's something else to fix on my end.

@matthewmayer
Copy link
Contributor

matthewmayer commented Jan 18, 2024

Per #2521 we want to prepare documentation for breaking changes in advance. Please insert this draft content at docs/guide/upgrading_v9/2472.md which will be inserted into the v9 migration guide once this is merged.

### Images now have random width, height and other options by default

`faker.image.url()` now returns an image url with a random width and height by default. To obtain the previous behavior, pass `{width: 640, height: 480}`.

`faker.image.urlLoremFlickr()` now returns an image url with a random width and height by default. To obtain the previous behavior, pass `{width: 640, height: 480}`.

`faker.image.urlPicsumPhotos()` now returns an image url with a random width and height by default, additionally images may be converted to grayscale and blurred at random. To obtain the previous behavior, pass `{width: 640, height: 480, blur: 0, grayscale: false}`

`faker.image.dataUri()` now returns an image url with a random width and height by default, additionally the type of the image is now random. To obtain the previous behavior, pass `{width: 640, height: 480, type: 'svg-uri'}`.

@olrtg olrtg requested a review from a team January 19, 2024 18:28
@olrtg
Copy link
Contributor Author

olrtg commented Jan 19, 2024

@matthewmayer done!

@ST-DDT ST-DDT removed the do NOT merge yet Do not merge this PR into the target branch yet label Feb 8, 2024
@ST-DDT ST-DDT changed the title refactor(image): randomize defaults refactor(image)!: randomize defaults Feb 8, 2024
@ST-DDT
Copy link
Member

ST-DDT commented Feb 8, 2024

Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Cannot be merged when next version is not a major release c: feature Request for new feature m: image Something is referring to the image module p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove defaults from image module
6 participants