mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-09-03 07:38:45 +02:00
fix transparent PNG signature issue
This commit is contained in:
@@ -15,7 +15,7 @@ import EmailComponent from "./component/emailComponent";
|
||||
import FieldsComponent from "./component/fieldsComponent";
|
||||
import Modal from "react-bootstrap/Modal";
|
||||
import ModalHeader from "react-bootstrap/esm/ModalHeader";
|
||||
import { getBase64FromIMG } from "../utils/Utils";
|
||||
import { convertPNGtoJPEG, getBase64FromIMG } from "../utils/Utils";
|
||||
import { useParams } from "react-router-dom";
|
||||
import Tour from "reactour";
|
||||
import { onSaveImage, onSaveSign } from "../utils/Utils";
|
||||
@@ -466,33 +466,7 @@ function SignYourSelf() {
|
||||
if (checkUrl) {
|
||||
ImgUrl = await getBase64FromIMG(ImgUrl + "?get");
|
||||
}
|
||||
|
||||
//function for convert signature png base64 url to jpeg base64
|
||||
const convertPNGtoJPEG = (base64Data) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const canvas = document.createElement("canvas");
|
||||
const img = new Image();
|
||||
img.src = base64Data;
|
||||
|
||||
img.onload = () => {
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
|
||||
const ctx = canvas.getContext("2d");
|
||||
ctx.drawImage(img, 0, 0);
|
||||
|
||||
// Convert to JPEG by using the canvas.toDataURL() method
|
||||
const jpegBase64Data = canvas.toDataURL("image/jpeg");
|
||||
|
||||
resolve(jpegBase64Data);
|
||||
};
|
||||
|
||||
img.onerror = (error) => {
|
||||
reject(error);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
convertPNGtoJPEG(ImgUrl)
|
||||
.then((jpegBase64Data) => {
|
||||
const removeBase64Fromjpeg = "data:image/jpeg;base64,";
|
||||
@@ -540,6 +514,11 @@ function SignYourSelf() {
|
||||
imgUrlList.map(async (url) => {
|
||||
let signUrl = url.SignUrl;
|
||||
|
||||
if (url.ImageType === "image/png") {
|
||||
//function for convert signature png base64 url to jpeg base64
|
||||
const newUrl = await convertPNGtoJPEG(signUrl);
|
||||
signUrl = newUrl;
|
||||
}
|
||||
const checkUrl = url.SignUrl.includes("https:");
|
||||
if (checkUrl) {
|
||||
signUrl = signUrl + "?get";
|
||||
@@ -550,21 +529,7 @@ function SignYourSelf() {
|
||||
})
|
||||
);
|
||||
images.forEach(async (imgData, id) => {
|
||||
let img;
|
||||
if (
|
||||
imgUrlList[id].ImageType &&
|
||||
imgUrlList[id].ImageType === "image/jpeg"
|
||||
) {
|
||||
img = await pdfDoc.embedJpg(imgData);
|
||||
} else if (
|
||||
imgUrlList[id].ImageType &&
|
||||
imgUrlList[id].ImageType === "image/png"
|
||||
) {
|
||||
img = await pdfDoc.embedPng(imgData);
|
||||
} else {
|
||||
img = await pdfDoc.embedPng(imgData);
|
||||
}
|
||||
|
||||
let img = await pdfDoc.embedJpg(imgData);
|
||||
const imgHeight = imgUrlList[id].Height
|
||||
? imgUrlList[id].Height
|
||||
: 60;
|
||||
|
||||
Reference in New Issue
Block a user