@xuda.io/ai_module 1.1.4442 → 1.1.4443
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.
- package/index.mjs +24 -5
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6548,22 +6548,41 @@ export const get_profile_picture = async function (uid, account_type = 'business
|
|
|
6548
6548
|
}
|
|
6549
6549
|
};
|
|
6550
6550
|
|
|
6551
|
+
// async function normalizeBase64To1024(base64Image) {
|
|
6552
|
+
// const inputBuffer = Buffer.from(base64Image, 'base64');
|
|
6553
|
+
|
|
6554
|
+
// const normalizedBuffer = await sharp(inputBuffer)
|
|
6555
|
+
// .resize(1024, 1024, {
|
|
6556
|
+
// fit: 'contain', // Preserve aspect ratio, fit within 211x211
|
|
6557
|
+
// background: { r: 0, g: 0, b: 0, alpha: 0 }, // Transparent background for padding
|
|
6558
|
+
// })
|
|
6559
|
+
// .png({
|
|
6560
|
+
// quality: 100,
|
|
6561
|
+
// compressionLevel: 9,
|
|
6562
|
+
// force: true,
|
|
6563
|
+
// })
|
|
6564
|
+
// .toBuffer();
|
|
6565
|
+
|
|
6566
|
+
// return normalizedBuffer.toString('base64'); // Return normalized base64 string
|
|
6567
|
+
// }
|
|
6568
|
+
|
|
6551
6569
|
async function normalizeBase64To1024(base64Image) {
|
|
6552
6570
|
const inputBuffer = Buffer.from(base64Image, 'base64');
|
|
6553
6571
|
|
|
6554
6572
|
const normalizedBuffer = await sharp(inputBuffer)
|
|
6555
6573
|
.resize(1024, 1024, {
|
|
6556
|
-
fit: '
|
|
6557
|
-
|
|
6574
|
+
fit: 'inside', // Scale up/down to fit inside 1024×1024 while preserving aspect ratio
|
|
6575
|
+
withoutEnlargement: false, // Allow enlargement if original is smaller
|
|
6576
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 }, // Still transparent padding
|
|
6558
6577
|
})
|
|
6559
6578
|
.png({
|
|
6560
|
-
quality:
|
|
6561
|
-
compressionLevel:
|
|
6579
|
+
quality: 98,
|
|
6580
|
+
compressionLevel: 8,
|
|
6562
6581
|
force: true,
|
|
6563
6582
|
})
|
|
6564
6583
|
.toBuffer();
|
|
6565
6584
|
|
|
6566
|
-
return normalizedBuffer.toString('base64');
|
|
6585
|
+
return normalizedBuffer.toString('base64');
|
|
6567
6586
|
}
|
|
6568
6587
|
|
|
6569
6588
|
const get_image_blob_from_downloaded_image = async function (url) {
|