@xuda.io/ai_module 1.1.4551 → 1.1.4552
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 +0 -67
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6067,73 +6067,6 @@ const create_ai_agent_image = async function (req, job_id, headers) {
|
|
|
6067
6067
|
const uniqueId = Date.now() + '_' + Math.random().toString(36).substring(7);
|
|
6068
6068
|
const tempOutputPath = path.join(tempDir, `output_${uniqueId}.png`);
|
|
6069
6069
|
|
|
6070
|
-
// async function normalizeBase64To1024(base64Image) {
|
|
6071
|
-
// const inputBuffer = Buffer.from(base64Image, 'base64');
|
|
6072
|
-
|
|
6073
|
-
// const normalizedBuffer = await sharp(inputBuffer)
|
|
6074
|
-
// .resize(1024, 1024, {
|
|
6075
|
-
// fit: 'contain', // Preserve aspect ratio, fit within 211x211
|
|
6076
|
-
// background: { r: 0, g: 0, b: 0, alpha: 0 }, // Transparent background for padding
|
|
6077
|
-
// })
|
|
6078
|
-
// .png({
|
|
6079
|
-
// quality: 100,
|
|
6080
|
-
// compressionLevel: 9,
|
|
6081
|
-
// force: true,
|
|
6082
|
-
// })
|
|
6083
|
-
// .toBuffer();
|
|
6084
|
-
|
|
6085
|
-
// return normalizedBuffer.toString('base64'); // Return normalized base64 string
|
|
6086
|
-
// }
|
|
6087
|
-
|
|
6088
|
-
// async function hasTransparentBackground(filePath) {
|
|
6089
|
-
// const image = sharp(filePath);
|
|
6090
|
-
// const metadata = await image.metadata();
|
|
6091
|
-
|
|
6092
|
-
// // If the image doesn't have an alpha channel at all → no transparency possible
|
|
6093
|
-
// if (!metadata.hasAlpha) {
|
|
6094
|
-
// return false;
|
|
6095
|
-
// }
|
|
6096
|
-
|
|
6097
|
-
// // For images with alpha channel, check if any pixel actually has alpha < 255
|
|
6098
|
-
// const { data, info } = await image.raw().toBuffer({ resolveWithObject: true });
|
|
6099
|
-
|
|
6100
|
-
// // Determine position of alpha channel based on number of channels
|
|
6101
|
-
// const channels = info.channels; // 2 (grayscale+alpha), 4 (RGBA), etc.
|
|
6102
|
-
// const alphaOffset = channels === 2 ? 1 : channels === 4 ? 3 : -1;
|
|
6103
|
-
|
|
6104
|
-
// if (alphaOffset === -1) {
|
|
6105
|
-
// // Unusual channel count – be conservative and assume it might have transparency
|
|
6106
|
-
// return true;
|
|
6107
|
-
// }
|
|
6108
|
-
|
|
6109
|
-
// for (let i = alphaOffset; i < data.length; i += channels) {
|
|
6110
|
-
// if (data[i] < 255) {
|
|
6111
|
-
// return true; // Found at least one transparent/semi-transparent pixel
|
|
6112
|
-
// }
|
|
6113
|
-
// }
|
|
6114
|
-
|
|
6115
|
-
// return false; // Has alpha channel but all pixels are fully opaque
|
|
6116
|
-
// }
|
|
6117
|
-
|
|
6118
|
-
// async function imageToPngBlob(filePath) {
|
|
6119
|
-
// const ext = path.extname(filePath).toLowerCase();
|
|
6120
|
-
|
|
6121
|
-
// let buffer;
|
|
6122
|
-
|
|
6123
|
-
// let is_transparent = false;
|
|
6124
|
-
// if (ext === '.png') {
|
|
6125
|
-
// buffer = await fs.promises.readFile(filePath);
|
|
6126
|
-
// is_transparent = await hasTransparentBackground(filePath);
|
|
6127
|
-
// } else {
|
|
6128
|
-
// console.log(`Converting ${path.basename(filePath)} to PNG...`);
|
|
6129
|
-
// buffer = await sharp(filePath).png({ quality: 100, compressionLevel: 9, force: true }).toBuffer();
|
|
6130
|
-
// }
|
|
6131
|
-
|
|
6132
|
-
// // Create a Blob with correct MIME type
|
|
6133
|
-
|
|
6134
|
-
// return { is_transparent, image_blob: new Blob([buffer], { type: 'image/png' }) };
|
|
6135
|
-
// }
|
|
6136
|
-
|
|
6137
6070
|
const { app_id, uid, ai_agent_id, tags, account_profile_info } = req;
|
|
6138
6071
|
|
|
6139
6072
|
const ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, ai_agent_id);
|