UNPKG

imagelogger

Version:

Shows an image in console.

26 lines (25 loc) 962 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jimp_1 = __importDefault(require("jimp")); async function convert(name, keep = 1) { const img = await jimp_1.default.read(name); const ary = []; for (let y = 0; y < img.getHeight(); y++) { ary[y] = []; if (y % keep == 0) { for (let x = 0; x < img.getWidth(); x++) { const col = img.getPixelColor(x, y).toString(16).padStart(8, '0'); ary[y][x] = { red: parseInt(col[0] + col[1], 16), green: parseInt(col[2] + col[3], 16), blue: parseInt(col[4] + col[5], 16) }; } } } return ary.filter(row => row.length !== 0); } exports.default = convert;