Skip to content

Commit

Permalink
Replace scale method with cover to better support non-standard albuma…
Browse files Browse the repository at this point in the history
…rt sizes.
  • Loading branch information
telekineticyeti committed Jan 19, 2023
1 parent 8acebe2 commit f5c29fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "subsonic-nowplaying-rgb-display",
"version": "0.0.1",
"version": "0.0.2",
"description": "Subsonic Now Playing album art for Taschen Flaschen RGB Matrix display",
"main": "./dist/index.js",
"files": [
Expand Down
19 changes: 13 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,22 @@ async function updateNowPlaying() {

// Read the image buffer and plot pixels to the FT image.
await Jimp.read(image).then(img => {
img.scaleToFit(config.ft_width, Jimp.AUTO, Jimp.RESIZE_BEZIER).contrast(0.1);

let w = img.getWidth(),
h = img.getHeight();
img
.cover(
config.ft_width,
config.ft_height,
Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE,
)
.contrast(0.1); // TODO - Add configuration of this to environment config.

// Update dimensions after scaling.
let width = img.getWidth();
let height = img.getHeight();

let pixelCount = 0;

for (let x = 0; x < w; x++) {
for (let y = 0; y < h; y++) {
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
let pixi = Jimp.intToRGBA(img.getPixelColor(x, y));
ftImage.plot(x, y, {r: pixi.r, g: pixi.g, b: pixi.b});
pixelCount++;
Expand Down

0 comments on commit f5c29fc

Please sign in to comment.