问题
Strangely my transparent image background become white after posting it on facebook page through graph api. This is my original image which has transparent background:
But after posting it on facebook I am getting this one which has white background:
For getting the original image link, I am checking the height and width of the image object from response and then just getting the source from it.
FB.api(
'/'+photoID,
'GET',
{"fields":"images"},
function(response) {
if (!response || response.error) {
reject(response.error);
} else {
var imageArray = response.images;
imageArray.forEach((item) => {
console.log(item.width);
if (item.width == imageWidth && item.height == imageHeight) {
resolve(item.source);
}
});
}
}
);
This is the full code for posting image on facebook:
function postImageOnFacebookPageAndGetPhotoID(url) {
return new Promise(function(resolve, reject) {
FB.api(
'/'+pageID+'/photos',
'POST',
{"url":url, "access_token":document.getElementById("pageAccessToken").value},
function(response) {
if (!response || response.error) {
reject(response.error);
} else {
resolve(response.id);
}
}
);
});
}
function getOriginalUploadedImageURL(photoID, imageWidth, imageHeight) {
return new Promise(function(resolve, reject) {
FB.api(
'/'+photoID,
'GET',
{"fields":"images"},
function(response) {
if (!response || response.error) {
reject(response.error);
} else {
var imageArray = response.images;
imageArray.forEach((item) => {
console.log(item.width);
if (item.width == imageWidth && item.height == imageHeight) {
resolve(item.source);
}
});
}
}
);
});
}
And this is how I am calling it:
postImageOnFacebookPageAndGetPhotoID(categoryIconUrl).then(
function(result) {
if (result) {
//Get the original image by photoID with the help of width and height
//Here result is the photoID
getOriginalUploadedImageURL(result, "66", "66").then(
function(result) {
if (result) {
//result is the original photo url of the uploaded image
console.log(result);
}
}).
catch(
function(error) {
alert(error);
}
)
}
}).
catch(
function(error) {
alert(error);
}
)
I need original transparent background image. What am I missing here?
Thanks!
来源:https://stackoverflow.com/questions/63306230/transparent-image-background-become-white-after-posting-on-facebook-page-by-grap