@@ -102,8 +102,8 @@ export class ImageModule extends ModuleBase {
102
102
* Generates a random image url.
103
103
*
104
104
* @param options Options for generating a URL for an image.
105
- * @param options.width The width of the image. Defaults to `640 `.
106
- * @param options.height The height of the image. Defaults to `480 `.
105
+ * @param options.width The width of the image. Defaults to random integer between `1` and `3999 `.
106
+ * @param options.height The height of the image. Defaults to random integer between `1` and `3999 `.
107
107
*
108
108
* @example
109
109
* faker.image.url() // 'https://loremflickr.com/640/480?lock=1234'
@@ -115,22 +115,26 @@ export class ImageModule extends ModuleBase {
115
115
/**
116
116
* The width of the image.
117
117
*
118
- * @default 640
118
+ * @default faker.number.int({ min: 1, max: 3999 })
119
119
*/
120
120
width ?: number ;
121
121
/**
122
122
* The height of the image.
123
123
*
124
- * @default 480
124
+ * @default faker.number.int({ min: 1, max: 3999 })
125
125
*/
126
126
height ?: number ;
127
127
} = { }
128
128
) : string {
129
- const { width = 640 , height = 480 } = options ;
129
+ const {
130
+ width = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
131
+ height = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
132
+ } = options ;
130
133
131
134
const urlMethod = this . faker . helpers . arrayElement ( [
132
135
this . urlLoremFlickr ,
133
- this . urlPicsumPhotos ,
136
+ ( { width, height } : { width ?: number ; height ?: number } ) =>
137
+ this . urlPicsumPhotos ( { width, height, grayscale : false , blur : 0 } ) ,
134
138
] ) ;
135
139
136
140
return urlMethod ( { width, height } ) ;
@@ -140,8 +144,8 @@ export class ImageModule extends ModuleBase {
140
144
* Generates a random image url provided via https://loremflickr.com.
141
145
*
142
146
* @param options Options for generating a URL for an image.
143
- * @param options.width The width of the image. Defaults to `640 `.
144
- * @param options.height The height of the image. Defaults to `480 `.
147
+ * @param options.width The width of the image. Defaults to random integer between `1` and `3999 `.
148
+ * @param options.height The height of the image. Defaults to random integer between `1` and `3999 `.
145
149
* @param options.category Category to use for the image.
146
150
*
147
151
* @example
@@ -157,13 +161,13 @@ export class ImageModule extends ModuleBase {
157
161
/**
158
162
* The width of the image.
159
163
*
160
- * @default 640
164
+ * @default faker.number.int({ min: 1, max: 3999 })
161
165
*/
162
166
width ?: number ;
163
167
/**
164
168
* The height of the image.
165
169
*
166
- * @default 480
170
+ * @default faker.number.int({ min: 1, max: 3999 })
167
171
*/
168
172
height ?: number ;
169
173
/**
@@ -172,7 +176,11 @@ export class ImageModule extends ModuleBase {
172
176
category ?: string ;
173
177
} = { }
174
178
) : string {
175
- const { width = 640 , height = 480 , category } = options ;
179
+ const {
180
+ width = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
181
+ height = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
182
+ category,
183
+ } = options ;
176
184
177
185
return `https://loremflickr.com/${ width } /${ height } ${
178
186
category == null ? '' : `/${ category } `
@@ -183,10 +191,10 @@ export class ImageModule extends ModuleBase {
183
191
* Generates a random image url provided via https://picsum.photos.
184
192
*
185
193
* @param options Options for generating a URL for an image.
186
- * @param options.width The width of the image. Defaults to `640 `.
187
- * @param options.height The height of the image. Defaults to `480 `.
188
- * @param options.grayscale Whether the image should be grayscale. Defaults to `false` .
189
- * @param options.blur Whether the image should be blurred. Defaults to `false `.
194
+ * @param options.width The width of the image. Defaults to random integer between `1` and `3999 `.
195
+ * @param options.height The height of the image. Defaults to random integer between `1` and `3999 `.
196
+ * @param options.grayscale Whether the image should be grayscale. Defaults to a random boolean value .
197
+ * @param options.blur Whether the image should be blurred. `0` disables the blur. Defaults to a random integer from `0` to `10 `.
190
198
*
191
199
* @example
192
200
* faker.image.urlPicsumPhotos() // 'https://picsum.photos/seed/NWbJM2B/640/480'
@@ -203,30 +211,35 @@ export class ImageModule extends ModuleBase {
203
211
/**
204
212
* The width of the image.
205
213
*
206
- * @default 640
214
+ * @default faker.number.int({ min: 1, max: 3999 })
207
215
*/
208
216
width ?: number ;
209
217
/**
210
218
* The height of the image.
211
219
*
212
- * @default 480
220
+ * @default faker.number.int({ min: 1, max: 3999 })
213
221
*/
214
222
height ?: number ;
215
223
/**
216
224
* Whether the image should be grayscale.
217
225
*
218
- * @default false
226
+ * @default faker.datatype.boolean()
219
227
*/
220
228
grayscale ?: boolean ;
221
229
/**
222
- * Whether the image should be blurred.
230
+ * Whether the image should be blurred. `0` disables the blur.
223
231
*
224
- * @default false
232
+ * @default faker.number.int({ max: 10 })
225
233
*/
226
- blur ?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 ;
234
+ blur ?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 ;
227
235
} = { }
228
236
) : string {
229
- const { width = 640 , height = 480 , grayscale = false , blur } = options ;
237
+ const {
238
+ width = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
239
+ height = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
240
+ grayscale = this . faker . datatype . boolean ( ) ,
241
+ blur = this . faker . number . int ( { max : 10 } ) ,
242
+ } = options ;
230
243
231
244
let url = `https://picsum.photos/seed/${ this . faker . string . alphanumeric ( {
232
245
length : { min : 5 , max : 10 } ,
@@ -350,10 +363,10 @@ export class ImageModule extends ModuleBase {
350
363
* Generates a random data uri containing an URL-encoded SVG image or a Base64-encoded SVG image.
351
364
*
352
365
* @param options Options for generating a data uri.
353
- * @param options.width The width of the image. Defaults to `640 `.
354
- * @param options.height The height of the image. Defaults to `480 `.
366
+ * @param options.width The width of the image. Defaults to random integer between `1` and `3999 `.
367
+ * @param options.height The height of the image. Defaults to random integer between `1` and `3999 `.
355
368
* @param options.color The color of the image. Must be a color supported by svg. Defaults to a random color.
356
- * @param options.type The type of the image. Defaults to `'svg-uri'` .
369
+ * @param options.type The type of the image. Defaults to a random type .
357
370
*
358
371
* @example
359
372
* faker.image.dataUri() // 'data:image/svg+xml;charset=UTF-8,%3Csvg%20xmlns%3D%22http...'
@@ -366,13 +379,13 @@ export class ImageModule extends ModuleBase {
366
379
/**
367
380
* The width of the image.
368
381
*
369
- * @default 640
382
+ * @default faker.number.int({ min: 1, max: 3999 })
370
383
*/
371
384
width ?: number ;
372
385
/**
373
386
* The height of the image.
374
387
*
375
- * @default 480
388
+ * @default faker.number.int({ min: 1, max: 3999 })
376
389
*/
377
390
height ?: number ;
378
391
/**
@@ -385,16 +398,16 @@ export class ImageModule extends ModuleBase {
385
398
* The type of the image to return. Consisting of
386
399
* the file extension and the used encoding.
387
400
*
388
- * @default 'svg-uri'
401
+ * @default faker.helpers.arrayElements([ 'svg-uri', 'svg-base64'])
389
402
*/
390
403
type ?: 'svg-uri' | 'svg-base64' ;
391
404
} = { }
392
405
) : string {
393
406
const {
394
- width = 640 ,
395
- height = 480 ,
407
+ width = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
408
+ height = this . faker . number . int ( { min : 1 , max : 3999 } ) ,
396
409
color = this . faker . color . rgb ( ) ,
397
- type = 'svg-uri' ,
410
+ type = this . faker . helpers . arrayElements ( [ 'svg-uri' , 'svg-base64' ] ) ,
398
411
} = options ;
399
412
400
413
const svgString = `<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="${ width } " height="${ height } "><rect width="100%" height="100%" fill="${ color } "/><text x="${
0 commit comments