@xuda.io/ai_module 1.1.4307 → 1.1.4308
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 +30 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -6751,6 +6751,36 @@ const get_business_logo = async function (uid, name, account_profile_info) {
|
|
|
6751
6751
|
};
|
|
6752
6752
|
|
|
6753
6753
|
const return_image_blob_from_downloaded_image = async function (url) {
|
|
6754
|
+
async function hasTransparentBackground(filePath) {
|
|
6755
|
+
const image = sharp(filePath);
|
|
6756
|
+
const metadata = await image.metadata();
|
|
6757
|
+
|
|
6758
|
+
// If the image doesn't have an alpha channel at all → no transparency possible
|
|
6759
|
+
if (!metadata.hasAlpha) {
|
|
6760
|
+
return false;
|
|
6761
|
+
}
|
|
6762
|
+
|
|
6763
|
+
// For images with alpha channel, check if any pixel actually has alpha < 255
|
|
6764
|
+
const { data, info } = await image.raw().toBuffer({ resolveWithObject: true });
|
|
6765
|
+
|
|
6766
|
+
// Determine position of alpha channel based on number of channels
|
|
6767
|
+
const channels = info.channels; // 2 (grayscale+alpha), 4 (RGBA), etc.
|
|
6768
|
+
const alphaOffset = channels === 2 ? 1 : channels === 4 ? 3 : -1;
|
|
6769
|
+
|
|
6770
|
+
if (alphaOffset === -1) {
|
|
6771
|
+
// Unusual channel count – be conservative and assume it might have transparency
|
|
6772
|
+
return true;
|
|
6773
|
+
}
|
|
6774
|
+
|
|
6775
|
+
for (let i = alphaOffset; i < data.length; i += channels) {
|
|
6776
|
+
if (data[i] < 255) {
|
|
6777
|
+
return true; // Found at least one transparent/semi-transparent pixel
|
|
6778
|
+
}
|
|
6779
|
+
}
|
|
6780
|
+
|
|
6781
|
+
return false; // Has alpha channel but all pixels are fully opaque
|
|
6782
|
+
}
|
|
6783
|
+
|
|
6754
6784
|
async function imageToPngBlob(filePath) {
|
|
6755
6785
|
const ext = path.extname(filePath).toLowerCase();
|
|
6756
6786
|
|