Open fengcppl opened 1 year ago
It looks like the selector is not working.
function openImageInPhotopea(originGallery) {
if (typeof originGallery.item === "function") {
originGallery = originGallery.item(0);
}
var imageSizeMatches = true;
const outgoingImg = originGallery.querySelectorAll("img")[0];
goToPhotopeaTab();
// First, check the image size to see if we have matching sizes. If it's bigger, we open it
// as a new document. Otherwise, we just append it to the current document as a new layer.
postMessageToPhotopea(getPhotopeaScriptString(getActiveDocumentSize)).then((response) => {
const activeDocSize = response[0].split(",");
if (outgoingImg.naturalWidth > activeDocSize[0] ||
outgoingImg.naturalHeight > activeDocSize[1]) {
imageSizeMatches = false;
}
blobTob64(outgoingImg.src, (imageData) => {
// Actually open the image, passing `imageSizeMatches` into Photopea's "open as new document" parameter.
postMessageToPhotopea(`app.open("${imageData}", null, ${imageSizeMatches});`, "*")
.then(() => {
if (imageSizeMatches) {
postMessageToPhotopea(`app.activeDocument.activeLayer.rasterize();`, "*");
} else {
postMessageToPhotopea(
`alert("New document created as the image sent is bigger than the active document");`,
"*");
}
});
});
});
}
fixed this issue by edit this function
function openImageInPhotopea(originGallery) { if (typeof originGallery.item === "function") { originGallery = originGallery.item(0); } var imageSizeMatches = true; const outgoingImg = originGallery.querySelectorAll("img")[0]; goToPhotopeaTab(); // First, check the image size to see if we have matching sizes. If it's bigger, we open it // as a new document. Otherwise, we just append it to the current document as a new layer. postMessageToPhotopea(getPhotopeaScriptString(getActiveDocumentSize)).then((response) => { const activeDocSize = response[0].split(","); if (outgoingImg.naturalWidth > activeDocSize[0] || outgoingImg.naturalHeight > activeDocSize[1]) { imageSizeMatches = false; } blobTob64(outgoingImg.src, (imageData) => { // Actually open the image, passing `imageSizeMatches` into Photopea's "open as new document" parameter. postMessageToPhotopea(`app.open("${imageData}", null, ${imageSizeMatches});`, "*") .then(() => { if (imageSizeMatches) { postMessageToPhotopea(`app.activeDocument.activeLayer.rasterize();`, "*"); } else { postMessageToPhotopea( `alert("New document created as the image sent is bigger than the active document");`, "*"); } }); }); }); }
通过编辑此功能修复了此问题
感谢提供解决方法 !