Skip to content

Commit

Permalink
Upgrade functions, replace sharp with jimp.
Browse files Browse the repository at this point in the history
  • Loading branch information
wizulus committed Dec 13, 2023
1 parent 8a1d608 commit 3ddae17
Show file tree
Hide file tree
Showing 10 changed files with 20,361 additions and 40,205 deletions.
23 changes: 5 additions & 18 deletions cli/src/ThumbnailGridGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Stream } from "stream";
import { storage } from "./FirebaseUtil";
import { meilisearch } from "./SearchManager";
import sharp from 'sharp';
import Jimp from 'jimp';
import chunk from "chunk";

/**
Expand All @@ -28,36 +28,23 @@ export default async function generateThumbnailGrid(width: number, height: numbe
const thumbWidth = 64;
const thumbHeight = 36;

const image = sharp({
create: {
width: thumbWidth * width,
height: thumbHeight * height,
channels: 4,
background: { r: 0, g: 0, b: 0, alpha: 0 },
}
});
const image = await new Jimp(thumbWidth * width, thumbHeight * height, 0x00000000);

// Add each thumbnail to the image.
const composites: sharp.OverlayOptions[] = [];
for (let i = 0; i < numThumbnails; i++) {
const x = i % width;
const y = Math.floor(i / width);

const img = thumbnails[i];
if (img === null) continue;

composites.push({
input: img,
left: x * thumbWidth,
top: y * thumbHeight,
});
const imgJimp = await Jimp.read(img);
image.composite(imgJimp, x * thumbWidth, y * thumbHeight);
}

image.composite(composites);

// Save the image to the output file.
console.log('Saving thumbnail grid...');
await image.png().toFile(outputFilePath);
await image.writeAsync(outputFilePath);

console.log('Thumbnail grid saved.');
}
Expand Down
Loading

1 comment on commit 3ddae17

@vercel
Copy link

@vercel vercel bot commented on 3ddae17 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.