Simple letter image generator.
It uses a canvas to generate an image binary.
ES Modules and CommonJS support.
For usage in a Node.js environment, will require the npm package 'node-canvas' (will use it instead of the dom).
Allows color and font customization:
-
Required entries:
-
Optional settings:
-
Color
- Letters color (random by default)
- Background color (random by default)
-
Font
- Font styles:
- Font variant:
- Font weight:
- Font family (not exhaustive list):
-
To install the package, just execute the following command:
$ npm install letter-image-generator
import generateLetterImage from "letter-image-generator";
Default
//Creates an image with the specified letter/s and size in px, default font style, variant, weight and font values
const img = generateLetterImage('L', 100);
Custom
- Passing settings as a variable
const allCustomSettings = {
style:'italic',
variant:'small-caps',
weight:'bold',
family:'Georgia',
lettersColor: '#ffffff',
backgroundColor: '#1eb3a4'
};
const custom = generateLetterImage('AC', 100, allCustomSettings);
- ... or inline settings
const customColors = generateLetterImage('sc', 100, {
lettersColor: '#c9142c', style: 'italic'
});
<html>
<body>
<img id="example" style="border-radius:50%" />
</body>
<script type="module">
//1. Import
import generateLetterImage from "letter-image-generator";
//2. Generate
// default: const img = generateLetterImage('L', 100);
// custom:
const img = generateLetterImage('Lig', 100, {style:'italic', weight:'lighter', family:'sans-serif'});
//3. Use
document.querySelector('#example').src = img;
</script>
</html>