Image
优质
小牛编辑
124浏览
2023-12-01
Random.image( size?, background?, foreground?, format?, text? )
- Random.image()
- Random.image( size )
- Random.image( size, background )
- Random.image( size, background, text )
- Random.image( size, background, foreground, text )
- Random.image( size, background, foreground, format, text )
生成一个随机的图片地址。
Random.image() 用于生成高度自定义的图片地址,一般情况下,应该使用更简单的 size
可选。
指示图片的宽高,格式为
'宽x高'
。默认从下面的数组中随机读取一个:[ '300x250', '250x250', '240x400', '336x280', '180x150', '720x300', '468x60', '234x60', '88x31', '120x90', '120x60', '120x240', '125x125', '728x90', '160x600', '120x600', '300x600' ]
background
可选。
指示图片的背景色。默认值为
'#000000'
。foreground
可选。
指示图片的前景色(文字)。默认值为
'#FFFFFF'
。format
可选。
指示图片的格式。默认值为
'png'
,可选值包括:'png'
、'gif'
、'jpg'
。text
可选。
指示图片上的文字。默认值为参数 size。
Random.image() // => "http://dummyimage.com/125x125" Random.image('200x100') // => "http://dummyimage.com/200x100" Random.image('200x100', '#fb0a2a') // => "http://dummyimage.com/200x100/fb0a2a" Random.image('200x100', '#02adea', 'Hello') // => "http://dummyimage.com/200x100/02adea&text=Hello" Random.image('200x100', '#00405d', '#FFF', 'Mock.js') // => "http://dummyimage.com/200x100/00405d/FFF&text=Mock.js" Random.image('200x100', '#ffcc33', '#FFF', 'png', '!') // => "http://dummyimage.com/200x100/ffcc33/FFF.png&text=!"Random.dataImage( size?, text? )
- Random.dataImage()
- Random.dataImage( size )
- Random.dataImage( size, text )
生成一段随机的 Base64 图片编码。
如果需要生成高度自定义的图片,请使用 size
可选。
指示图片的宽高,格式为
'宽x高'
。默认从下面的数组中随机读取一个:[ '300x250', '250x250', '240x400', '336x280', '180x150', '720x300', '468x60', '234x60', '88x31', '120x90', '120x60', '120x240', '125x125', '728x90', '160x600', '120x600', '300x600' ]text
可选。
指示图片上的文字。默认值为参数 size。
图片的背景色是随机的,取值范围参考自 http://brandcolors.net/。
Random.dataImage() // => "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA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