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