Skip to content

Commit

Permalink
chore: upgrade jimp (sveltejs#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann authored Sep 2, 2024
1 parent ca81e1d commit df643cd
Show file tree
Hide file tree
Showing 4 changed files with 268 additions and 453 deletions.
2 changes: 1 addition & 1 deletion apps/svelte.dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"degit": "^2.8.4",
"dotenv": "^16.4.5",
"esbuild": "^0.20.2",
"jimp": "^0.22.12",
"jimp": "^1.1.1",
"lightningcss": "^1.25.1",
"magic-string": "^0.30.10",
"marked": "^12.0.2",
Expand Down
19 changes: 9 additions & 10 deletions apps/svelte.dev/scripts/get_contributors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import 'dotenv/config';
import Jimp from 'jimp';
import { Jimp } from 'jimp';
import { stat, writeFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -46,27 +46,26 @@ try {
.sort((a, b) => b.contributions - a.contributions)
.slice(0, MAX);

const sprite = new Jimp(SIZE * authors.length, SIZE);
const sprite = new Jimp({ width: SIZE * authors.length, height: SIZE });

for (let i = 0; i < authors.length; i += 1) {
const author = authors[i];
console.log(`${i + 1} / ${authors.length}: ${author.login}`);

const image_data = await fetch(author.avatar_url);
const buffer = await image_data.arrayBuffer();
const image = await Jimp.fromBuffer(buffer);

// @ts-ignore
const image = await Jimp.read(buffer);
image.resize(SIZE, SIZE);
image.resize({ w: SIZE, h: SIZE });

sprite.composite(image, i * SIZE, 0);
}

await sprite
.quality(80)
.writeAsync(
fileURLToPath(new URL(`../src/routes/_home/Supporters/contributors.jpg`, import.meta.url))
);
await sprite.write(
// @ts-expect-error
fileURLToPath(new URL(`../src/routes/_home/Supporters/contributors.jpg`, import.meta.url)),
{ quality: 80 }
);

const str = `[\n\t${authors.map((a) => `'${a.login}'`).join(',\n\t')}\n]`;

Expand Down
21 changes: 11 additions & 10 deletions apps/svelte.dev/scripts/get_donors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-check
import 'dotenv/config';
import Jimp from 'jimp';
import { Jimp } from 'jimp';
import { stat, writeFile } from 'node:fs/promises';
import { dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
Expand Down Expand Up @@ -42,25 +42,26 @@ try {
try {
const image_data = await fetch(backer.image);
const buffer = await image_data.arrayBuffer();
// @ts-ignore
const image = await Jimp.read(buffer);
image.resize(SIZE, SIZE);
const image = await Jimp.fromBuffer(buffer);

image.resize({ w: SIZE, h: SIZE });

included.push({ backer, image });
} catch (err) {
console.log(`Skipping ${backer.name}: no image data`);
}
}

const sprite = new Jimp(SIZE * included.length, SIZE);
const sprite = new Jimp({ width: SIZE * included.length, height: SIZE });
for (let i = 0; i < included.length; i += 1) {
sprite.composite(included[i].image, i * SIZE, 0);
}

await sprite
.quality(80)
.writeAsync(
fileURLToPath(new URL(`../src/routes/_home/Supporters/donors.jpg`, import.meta.url))
);
await sprite.write(
// @ts-expect-error
fileURLToPath(new URL(`../src/routes/_home/Supporters/donors.jpg`, import.meta.url)),
{ quality: 80 }
);

const str = `[\n\t${included.map((a) => `${JSON.stringify(a.backer.name)}`).join(',\n\t')}\n]`;

Expand Down
Loading

0 comments on commit df643cd

Please sign in to comment.