@maioradv/nestjs-core 1.5.1 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,9 +17,30 @@ let ImageCompressionPipe = class ImageCompressionPipe {
|
|
|
17
17
|
//private readonly logger = LoggerFactory(this.constructor.name);
|
|
18
18
|
async transform(file, metadata) {
|
|
19
19
|
try {
|
|
20
|
-
const compressedBuffer = await (
|
|
21
|
-
|
|
22
|
-
}).rotate().toBuffer()
|
|
20
|
+
/*const compressedBuffer = await sharp(file.buffer).webp({
|
|
21
|
+
quality: 70,
|
|
22
|
+
}).rotate().toBuffer()*/
|
|
23
|
+
const image = (0, sharp_1.default)(file.buffer);
|
|
24
|
+
const metadata = await image.metadata();
|
|
25
|
+
const compressedBuffer = await image
|
|
26
|
+
.resize({
|
|
27
|
+
width: metadata.width > metadata.height ? 1920 : null,
|
|
28
|
+
height: metadata.height > metadata.width ? 1920 : null,
|
|
29
|
+
fit: 'inside',
|
|
30
|
+
})
|
|
31
|
+
.withMetadata() // Mantieni il profilo colore e i metadati dell'immagine originale
|
|
32
|
+
.webp({ quality: 90 }) // Alta qualità per mantenere la nitidezza
|
|
33
|
+
.rotate()
|
|
34
|
+
.toBuffer();
|
|
35
|
+
/*const thumbnailBuffer = await sharp(file.buffer)
|
|
36
|
+
.resize({
|
|
37
|
+
width: 128,
|
|
38
|
+
height: 300,
|
|
39
|
+
fit: 'cover', // Ritaglia l'immagine per adattarsi a 128x300 mantenendo le proporzioni
|
|
40
|
+
position: 'center', // Centra l'immagine durante il ritaglio
|
|
41
|
+
})
|
|
42
|
+
.webp({ quality: 70 })
|
|
43
|
+
.toBuffer();*/
|
|
23
44
|
file.buffer = compressedBuffer;
|
|
24
45
|
file.mimetype = 'image/webp';
|
|
25
46
|
file.size = compressedBuffer.length;
|