Skip to content

Commit

Permalink
feat: use heic-convert
Browse files Browse the repository at this point in the history
  • Loading branch information
2paperstar committed Nov 23, 2023
1 parent f1b0fff commit f1b2ee4
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 11 deletions.
106 changes: 99 additions & 7 deletions package-lock.json

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

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"config": {
"libvips": "8.14.3"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.338.0",
"@nestjs/axios": "^2.0.0",
Expand All @@ -39,6 +36,7 @@
"cookie-parser": "^1.4.6",
"dayjs": "^1.11.9",
"firebase-admin": "^11.9.0",
"heic-convert": "^2.0.0",
"html-to-text": "^9.0.5",
"multer": "^1.4.5-lts.1",
"mysql2": "^3.2.4",
Expand All @@ -47,7 +45,7 @@
"path": "^0.12.7",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0",
"sharp": "^0.32.4",
"sharp": "^0.32.6",
"ts-case-convert": "^2.0.2"
},
"devDependencies": {
Expand All @@ -58,6 +56,7 @@
"@types/cookie-parser": "^1.4.3",
"@types/cron": "^2.0.1",
"@types/express": "^4.17.13",
"@types/heic-convert": "^1.2.3",
"@types/html-to-text": "^9.0.1",
"@types/jest": "29.2.4",
"@types/multer": "^1.4.7",
Expand Down
9 changes: 9 additions & 0 deletions src/image/image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
NotFoundException,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import convert from 'heic-convert';
import sharp from 'sharp';

@Injectable()
Expand Down Expand Up @@ -118,6 +119,14 @@ export class ImageService {
}

private async convertToWebp(file: Express.Multer.File): Promise<Buffer> {
if (file.mimetype === 'image/heic' || file.mimetype === 'image/heif') {
const jpeg = await convert({
buffer: file.buffer,
format: 'PNG',
quality: 1,
});
return sharp(jpeg).webp().toBuffer();
}
return sharp(file.buffer).webp().toBuffer();
}
}

0 comments on commit f1b2ee4

Please sign in to comment.