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

faker.image.dataUri is not random #2307

Closed
matthewmayer opened this issue Aug 12, 2023 · 15 comments · Fixed by #2316
Closed

faker.image.dataUri is not random #2307

matthewmayer opened this issue Aug 12, 2023 · 15 comments · Fixed by #2316
Assignees
Labels
c: bug Something isn't working good first issue Good for newcomers m: image Something is referring to the image module p: 1-normal Nothing urgent
Milestone

Comments

@matthewmayer
Copy link
Contributor

matthewmayer commented Aug 12, 2023

faker.image.dataUri is not random, it always returns the same image (a grey rectangle with the provided width/height in text)

https://stackblitz.com/edit/faker-js-demo-quium5?file=index.ts

Source: https://github.com/faker-js/faker/blob/651d1a8c/src/modules/image/index.ts#L373

I also noted that the width x height text doesn't fit for small width parameters


Originally posted by @ST-DDT in #2273 (comment)

@matthewmayer
Copy link
Contributor Author

Possible options

  • make the color random? (but only works if color is NOT provided)
  • add a random word e.g. from faker.lorem.word() in addition to the width x height text?
  • pick two points and add a random line or rectangle somewhere in the SVG?

@matthewmayer matthewmayer added c: bug Something isn't working good first issue Good for newcomers p: 1-normal Nothing urgent m: image Something is referring to the image module labels Aug 12, 2023
@ghost
Copy link

ghost commented Aug 12, 2023

Making the color random if it is not provided is a great idea.

I also like the other two ideas. A quite similar option would be to add a random shape somewhere in the SVG.

@ST-DDT
Copy link
Member

ST-DDT commented Aug 14, 2023

I created an issue for the (other) image functions as well.

@matthewmayer
Copy link
Contributor Author

better idea we could put a random emoji in the middle instead of a random word, then its locale indepdendent and you don't need to worry about the text being too long.

@OmkarPednekar
Copy link
Contributor

OmkarPednekar commented Aug 14, 2023

Hey @ST-DDT this my first time contributing to a Open Source Project
This is the code which I have added to generate random color if color option is not provided is this correct? It creates a random HEX Color code
image

@ST-DDT
Copy link
Member

ST-DDT commented Aug 14, 2023

Close but we dont use Math.random because we want reproducible values. So we usually use faker.helpers.arrayElement or faker.number.int for that.

For this case specifically we already have a method that can generate rgb colors:
https://fakerjs.dev/api/color.html#rgb

@OmkarPednekar
Copy link
Contributor

OmkarPednekar commented Aug 14, 2023

so I should use that?
image

@ST-DDT
Copy link
Member

ST-DDT commented Aug 14, 2023

I would probably inline that and omit the args matching the defaults but yes.
Does svg only support lowercase rgb colors and not upper or mixed ones?

@OmkarPednekar
Copy link
Contributor

It supports all

@OmkarPednekar
Copy link
Contributor

OmkarPednekar commented Aug 14, 2023

Please Check my PR: #2316

@matthewmayer
Copy link
Contributor Author

Any thoughts on including an emoji or a random shape/line? if we're going to do changes to this method to make it more random may as well do it all in one PR.

@ST-DDT
Copy link
Member

ST-DDT commented Aug 14, 2023

I think we could randomly use one of these overlays:

  • a random word
  • a random emoji
  • a random shape

(plus a new textColor, featureColor, or whateverColor option)

@matthewmayer
Copy link
Contributor Author

if we omit random word it will still work in the base locale

@ST-DDT
Copy link
Member

ST-DDT commented Aug 14, 2023

Well, if we argue like that then what if we don't have any locale data?
Then only a shape will work.
Maybe a "shuffle + first working" concept might be more safe in that regard.

Would the "feature"/"overlay" replace the current dimension text? (or would it be a 4th option?)

@matthewmayer
Copy link
Contributor Author

think the dimenson text is useful so i'd probably do it next to / below / above the existing dimension text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working good first issue Good for newcomers m: image Something is referring to the image module p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants