set scale when generating png

This commit is contained in:
Júlio César Batista 2023-04-11 14:38:44 -03:00
parent cbd1afeaef
commit 1b8122b0f9
No known key found for this signature in database
GPG key ID: 10C4B861BF314878
2 changed files with 8 additions and 5 deletions

View file

@ -1,18 +1,18 @@
async (imgString) => {
async ({imgString, scale}) => {
const tempImg = new Image();
const loadImage = () => {
return new Promise((resolve, reject) => {
tempImg.onload = (event) => resolve(event.currentTarget);
tempImg.onerror = () => {
reject("error loading string as an image");
reject("error loading string as an image:\n" + imgString);
};
tempImg.src = imgString;
});
};
const img = await loadImage();
const canvas = document.createElement("canvas");
canvas.width = img.width * 2;
canvas.height = img.height * 2;
canvas.width = img.width * scale;
canvas.height = img.height * scale;
const ctx = canvas.getContext("2d");
if (!ctx) {
return new Error("could not get canvas context");

View file

@ -95,7 +95,10 @@ func ConvertSVG(ms *xmain.State, page playwright.Page, svg []byte) ([]byte, erro
defer cancel()
encodedSVG := base64.StdEncoding.EncodeToString(svg)
pngInterface, err := page.Evaluate(genPNGScript, "data:image/svg+xml;charset=utf-8;base64,"+encodedSVG)
pngInterface, err := page.Evaluate(genPNGScript, map[string]interface{}{
"imgString": "data:image/svg+xml;charset=utf-8;base64," + encodedSVG,
"scale": int(SCALE),
})
if err != nil {
return nil, fmt.Errorf("failed to generate png: %w", err)
}