waifu-generator
Write random anime girl pictures on file system, using Nodejs, thanks to thiswaifudoesnotexist.net
Usecase ?
You need to generate random pngs for testing purposes, but js-image-generator is definitely too efficient and boring for the job?
Look no further! TheRealBarenziah(tm) brings you this StyleGAN2-empowered*,industrial grade, uwu-compliant, yet unlicensed module!
Compatibility
node >= 8 (we're using promises)
Use
npm i --save-dev waifu-generator
tl;dr
options
object is facultativeoptions.filename
default to nulloptions.path
default to nulloptions.skipFs
default to false; pass true
to skip the fs.createWriteStream() calloptions.withoutPrefix
default to false; pass true
to remove 'data:image/png;base64,' prefix from returned stringoptions.mosaic
default to null; enable to create a mosaic of waifus. Infos here
The Long Read
Case 1 : default (no option object)
In your generate.js
file :
const generateWaifu = require("waifu-generator");
generateWaifu()
.then(res => console.log(res))
.catch(e => console.error(e));
Back in terminal (for the example):
node ./generate.js
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=
Case 2 : providing an option object
In your generate.js
file :
const generateWaifu = require("waifu-generator");
const options = {
filename: "sugoi_kawaii",
path: "./__TESTS__/images"
};
generateWaifu(options);
Back in terminal:
node ./generate.js
Case 2.5: skip the fs call
Sometimes, you don't want your tests to do I/O operations (typically when you're after performance). In that case you can skip the filesystem call entierely, leaving you to work with pure base64 strings, ready to be allocated.
Barebone example:
const generateWaifu = require("waifu-generator");
const yourCustomFunc = async () => {
const base64waifu = await generateWaifu({ skipFs: true });
const output = base64waifu.toString().toString().toString();
console.log(output);
return output;
};
yourCustomFunc();
NB: Activating skipFs
will indeed make the path/filename options irrelevant !
Mosaic
Available from 2.0.0 onward. Opt-in by defining option.mosaic
:
tl;dr
const waifuGenerator = require("./index")
waifuGenerator({
filename: "mosaic",
mosaic: {
number: 2,
options: {
direction: true,
color: 0x000000
}
}
})
Full story
Made this a major release because it adds some bloat (jimp + merge-img dependencies).
If you don't need this feature, you better stick to good ol' 1.1.1
So why this update ?
Initial pool of images being only 100000, there was a chance to get duplicates.
Also, I needed to be able to generate some FAT files (>32Mb and >64Mb) for my test suite.
This option will generate a mosaic of waifus so the possibilities becomes 100000
* a lot
.
The option.mosaic.number
param is mandatory and must be in the 1-99 range.
The option.mosaic.options
is optional: it enable you to use merge-img option object in case you need it.
With this the possibilities becomes 100000
* a lot
* A LOT
.
I know math, you can twust this number owo. Example output with mosaic.number = 3
:
Clean your mess
This (somewhat) unbloated module doesn't support file deletion. To do that, it's your responsibility, as a developer, to chose the correct approach between using the awesome fs API, using higher level libs, or going for OS level operation.
..Of course you're also free to skip the hassle by using the skipFs
parameter !
Take advantage of this module being unlicensed: please fork away and write the best solution for your specific need :)
BTW
Please don't read this seriously. This JavaScript does little more than exploiting the awesome work that was done on thiswaifudoesnotexist, so please pay them a visit and click their footer links :)