diff options
| author | Kevin Yue <[email protected]> | 2018-08-13 00:05:19 +0800 |
|---|---|---|
| committer | Kevin Yue <[email protected]> | 2018-08-13 00:05:19 +0800 |
| commit | 3448b0afcecfa5bf26d5716594347f76496d400b (patch) | |
| tree | e36c51fba8d50dafc559538345caa13eb04beb41 /lib | |
| parent | 1605703565046c40f3d4b5ff318ff2d5846c8685 (diff) | |
| download | faker-3448b0afcecfa5bf26d5716594347f76496d400b.tar.xz faker-3448b0afcecfa5bf26d5716594347f76496d400b.zip | |
Added custom background color to data URI image
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/image.js | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/image.js b/lib/image.js index 311acee4..b25b5895 100644 --- a/lib/image.js +++ b/lib/image.js @@ -201,10 +201,12 @@ var Image = function (faker) { * * @param {number} width * @param {number} height + * @param {string} color * @method faker.image.dataUri */ - self.dataUri = function (width, height) { - var svgString = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="full" width="' + width + '" height="' + height + '"><rect width="100%" height="100%" fill="grey"/><text x="' + width / 2 + '" y="' + height / 2 + '" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">' + width + 'x' + height + '</text></svg>'; + self.dataUri = function (width, height, color) { + color = color || 'grey'; + var 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="' + width / 2 + '" y="' + height / 2 + '" font-size="20" alignment-baseline="middle" text-anchor="middle" fill="white">' + width + 'x' + height + '</text></svg>'; var rawPrefix = 'data:image/svg+xml;charset=UTF-8,'; return rawPrefix + encodeURIComponent(svgString); }; |
