Basic preparation

environment

  • Node.js (LTS) versions such as 16.x are installed.
  • Package Manager Yarn: npm i -g yarn
  • Redis: cache service, it is best to prepare another one by yourself

Project preparation

  • Create output directory
  • Execute the command yarn install dependencies

test environment:

 node 1-seeds.js

See if it can run without error.

Ready to work

Picture material preparation

Create a source directory, and place the picture materials according to the type.

Image material requirements:

  • png format
  • Transparent Background
  • Uniform size

    Reference directory structure:
    在这里插入图片描述

Probability of preparing material

For 5000 generated products, it is recommended to provide at least 4 types of materials for arrangement and combination. If the material probability is not enough to generate, executing the code in step 1 will cause an infinite loop (it does not end, it needs to be terminated manually).

Reference Code:

 // 概率自行调整,总数等于 TOTAL
const RATE = {
  background: [
    //
    3.0 * 50,
    6.3 * 50,
    7.0 * 50,
    7.0 * 50,
    7.0 * 50,
    7.0 * 50,
    8.0 * 50,
    8.0 * 50,
    8.0 * 50,
    8.0 * 50,
    8.0 * 50,
    8.0 * 50,
    8.0 * 50,
    6.7 * 50
  ],
  prop: [
    //
    2.5 * 50,
    5.0 * 50,
    5.0 * 50,
    5.0 * 50,
    5.5 * 50,
    5.5 * 50,
    5.5 * 50,
    5.5 * 50,
    5.4 * 50,
    5.6 * 50,
    6.0 * 50,
    6.0 * 50,
    7.5 * 50,
    7.5 * 50,
    7.5 * 50,
    7.5 * 50,
    7.5 * 50
  ],
  character: [
    0.5 * 50,
    0.8 * 50,
    0.8 * 50,
    0.8 * 50,
    0.8 * 50,
    1.0 * 50,
    1.0 * 50,
    1.2 * 50,
    1.2 * 50,
    1.2 * 50,
    1.5 * 50,
    1.5 * 50,
    1.5 * 50,
    1.5 * 50,
    1.5 * 50,
    1.5 * 50,
    1.5 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.52 * 50,
    1.56 * 50,
    1.0 * 50,
    1.3 * 50,
    1.3 * 50,
    1.3 * 50,
    1.5 * 50,
    1.6 * 50,
    1.6 * 50,
    1.6 * 50,
    1.6 * 50,
    1.6 * 50,
    1.6 * 50,
    1.7 * 50,
    2.0 * 50,
    2.0 * 50,
    2.0 * 50,
    2.0 * 50,
    2.0 * 50,
    2.0 * 50,
    2.3 * 50,
    2.5 * 50,
    2.5 * 50,
    2.8 * 50,
    2.8 * 50,
    2.5 * 50,
    2.5 * 50,
    2.5 * 50,
    2.8 * 50,
    2.5 * 50,
    2.5 * 50,
    2.5 * 50
  ]
};

generate

0. Modify the configuration

First of all, you need to modify the probability and total number of each type in 1-seeds.js .

Then you need to modify the type stacking order in generate.js .

1. Generate seeds

 node 1-seeds.js > 概率.log

Be sure to make sure the probability is reasonable.

2. Batch generation tasks

 node 2-task.js
node 3-handle.js

If an error is reported in the middle, modify the corresponding material or probability. Then clear the Redis cache and start over.

在这里插入图片描述
The process can be stopped manually until the number of builds reaches the expected number.

FAQ Questions and Answers

Environment related

For those who don't know Node.js and Redis, they need to Baidu by themselves, which are very basic.

Dependency installation

Canvas dependencies:

OS Command
OS X Using Homebrew :<br/> brew install pkg-config cairo pango libpng jpeg giflib librsvg
Ubuntu sudo apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
Fedora sudo yum install gcc-c++ cairo-devel pango-devel libjpeg-turbo-devel giflib-devel
Solaris pkgin install cairo pango pkg-config xproto renderproto kbproto xextproto
OpenBSD doas pkg_add cairo pango png jpeg giflib
Windows See the wiki
Others See the wiki

Please pm for project guidance.


willin
213 声望12 粉丝

欢迎在各平台 Follow 我。