@xuda.io/ai_module 1.1.4304 → 1.1.4306
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 +20 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6739,6 +6739,8 @@ const get_business_logo = async function (uid, name, account_profile_info) {
|
|
|
6739
6739
|
|
|
6740
6740
|
const url = ret.data;
|
|
6741
6741
|
const file = await return_image_blob_from_downloaded_image(url);
|
|
6742
|
+
|
|
6743
|
+
console.log(file);
|
|
6742
6744
|
// prompt: `find "${name}" logo base on the following facts "${facts}", Return only png,jpg img tag , nothing else`,
|
|
6743
6745
|
// try {
|
|
6744
6746
|
// if (ret.code > -1) {
|
|
@@ -6749,6 +6751,24 @@ const get_business_logo = async function (uid, name, account_profile_info) {
|
|
|
6749
6751
|
};
|
|
6750
6752
|
|
|
6751
6753
|
const return_image_blob_from_downloaded_image = async function (url) {
|
|
6754
|
+
async function imageToPngBlob(filePath) {
|
|
6755
|
+
const ext = path.extname(filePath).toLowerCase();
|
|
6756
|
+
|
|
6757
|
+
let buffer;
|
|
6758
|
+
|
|
6759
|
+
let is_transparent = false;
|
|
6760
|
+
if (ext === '.png') {
|
|
6761
|
+
buffer = await fs.promises.readFile(filePath);
|
|
6762
|
+
is_transparent = await hasTransparentBackground(filePath);
|
|
6763
|
+
} else {
|
|
6764
|
+
console.log(`Converting ${path.basename(filePath)} to PNG...`);
|
|
6765
|
+
buffer = await sharp(filePath).png({ quality: 100, compressionLevel: 9, force: true }).toBuffer();
|
|
6766
|
+
}
|
|
6767
|
+
|
|
6768
|
+
// Create a Blob with correct MIME type
|
|
6769
|
+
|
|
6770
|
+
return { is_transparent, image_blob: new Blob([buffer], { type: 'image/png' }) };
|
|
6771
|
+
}
|
|
6752
6772
|
try {
|
|
6753
6773
|
if (!url) {
|
|
6754
6774
|
throw new Error('No URL provided in request');
|