list-gen
A simple helper package for generating lists in JIMP.
Basic Usage
const lines = 'Item #1' 'Item #2' '...'; const options = /* Initial XY Coordinates - Optional, indicates where the first line of text will be placed on the page */ initialXY: 50 100 // Page 1 50 20 // Page >= 2 (Optional) /* Line Spacing - Optional, a function which modifies x, y values passed through it */ { return x y + 40; // This example adds 40px to the y value every new line } /* Write Image - Optional, when specified, outputs .jpg files in addition to returning buffer(s) */ write: './output/' /* Max Lines - Optional, forces a new page when X amount of lines are on the page */ maxLines: 25 // Page 1 40 // Page >= 2 (Optional) /* First Background - Required, the image background displayed on the first (or subsequent) page */ firstBG: './bg-1.png' /* Extra Backgrounds - Optional, the image background displayed on pages 2 and above */ extraBG: './bg-2.png' /* Font - Optional, the font to be used, has to be compatible with Jimp */ font: './myFont.fnt';
const List = ; // Require Package const list = lines options; // Create List Objectconst resp = await list; // Generate list
Examples
Use yarn test
or npm run test
to compile these yourself
1. Basic todo list | Output
const list = ...22 initialXY: 420 420 x y + 963 firstBG: path write: path font: JimpFONT_SANS_128_BLACK ;await list;
2. Pixel Art Theme | Output
const list = ...200 initialXY: 60 280 // Page 1 60 10 // Page >= 2 { if pageNumber === 0 y += remainingLineslength % 6 === 0 ? 2 : 0; // Every 6 items on the first page, add 2 to the y position return x y + 40; } maxLines: 41 48 write: path firstBG: path extraBG: path font: path ;await list;
3. Staircase Style | Output
const list = ...10 initialXY: 0 5 x + 100 y + 25 write: path firstBG: path ;await list;