Skip to content

Commit

Permalink
Add missing types. Update image creatIcon logic for heic files
Browse files Browse the repository at this point in the history
  • Loading branch information
Vafilor committed Dec 20, 2023
1 parent a76b2a5 commit 161f1c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
7 changes: 7 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@electron-forge/plugin-auto-unpack-natives": "^7.2.0",
"@electron-forge/plugin-webpack": "^7.2.0",
"@types/heic-convert": "^1.2.3",
"@types/heic-decode": "^1.1.2",
"@types/jest": "^29.5.11",
"@types/react": "^18.2.39",
"@types/react-dom": "^18.2.17",
Expand Down
13 changes: 5 additions & 8 deletions src/server/image.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import { extname } from "node:path";

import convert from "heic-convert";
import sharp from "sharp";
import decode from 'heic-decode';

import { readFile, writeFile } from "node:fs/promises";
import { readFile } from "node:fs/promises";

export async function createIcon(inputPath: string, outputPath: string, width: number, height: number): Promise<void> {
const ext = extname(inputPath).toLowerCase();

if (ext === ".heic") {
const inputBuffer = await readFile(inputPath);
const outputBuffer = await convert({
buffer: inputBuffer,
format: 'JPEG',
quality: 1
});
const { data, width: imageWidth, height: imageHeight } = await decode({ buffer: inputBuffer });

await writeFile(outputPath, Buffer.from(outputBuffer));
// TODO 4 is a guess - need to validate
await sharp(data, { raw: { width: imageWidth, height: imageHeight, channels: 4 } }).resize(width, height).jpeg().toFile(outputPath);
} else {
await sharp(inputPath).resize(width, height).jpeg().toFile(outputPath);
}
Expand Down

0 comments on commit 161f1c3

Please sign in to comment.