imagelogger
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -0,1 +1,3 @@ | ||
#!/usr/env/bin node | ||
"use strict"; | ||
@@ -2,0 +4,0 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { |
@@ -0,1 +1,3 @@ | ||
#!/usr/env/bin node | ||
import { readFileSync } from 'fs'; | ||
@@ -2,0 +4,0 @@ import log, { Pixel, Image } from './main' |
@@ -0,1 +1,3 @@ | ||
#!/usr/env/bin node | ||
"use strict"; | ||
@@ -2,0 +4,0 @@ var __importDefault = (this && this.__importDefault) || function (mod) { |
@@ -0,1 +1,3 @@ | ||
#!/usr/env/bin node | ||
import { writeFileSync } from 'fs'; | ||
@@ -2,0 +4,0 @@ import convert from './converter'; |
import Jimp from 'jimp'; | ||
import { Pixel } from './main'; | ||
export default async function convert(name: string, keep: number = 1): Promise<Pixel[][]> { | ||
/** | ||
* | ||
* @param name Filename. | ||
* @param heightScale Resulting image height will be `originalHeight * (1/(heightScale * widthScale))` (approximately) | ||
* @param widthScale Resulting image width will be `originalWidth * (1/widthScale)` (approximately) | ||
*/ | ||
export default async function convert(name: string, heightScale: number = 1, widthScale: number = 1): Promise<Pixel[][]> { | ||
const img = await Jimp.read(name); | ||
@@ -11,10 +17,14 @@ | ||
ary[y] = []; | ||
if (y % keep == 0) { | ||
if (y % heightScale == 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) | ||
} as Pixel | ||
if (x % widthScale == 0) { | ||
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) | ||
} as Pixel | ||
} else { | ||
ary[y][x] = null; | ||
} | ||
} | ||
@@ -24,3 +34,3 @@ } | ||
return ary.filter(row => row.length !== 0); | ||
return ary.filter(row => row.length !== 0).map(row => row.filter(cell => cell !== null)); | ||
} |
{ | ||
"name": "imagelogger", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Shows an image in console.", | ||
@@ -23,5 +23,5 @@ "main": "main.js", | ||
"bin": { | ||
"logimage": "cli", | ||
"convert-to-image": "cliconv" | ||
"logimage": "./cli.js", | ||
"convert-to-image": "./cliconv.js" | ||
} | ||
} |
5567643
321
22