hi I want to rotate my PNG with this code below :
async function rotateImage(imageBase64, rotation) {
var img = new Image();
img.src = imageBase64;
return new Promise(resolve => {
img.onload = () => {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = img.width;
canvas.height = img.height;
ctx.fillStyle = "rgba(255,255,255,.6)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.save();
ctx.translate(canvas.width / 2, canvas.height / 2)
ctx.rotate(rotation * (Math.PI / 180));
ctx.drawImage(img, -img.width / 2, -img.height / 2);
ctx.restore();
resolve(canvas.toDataURL("image/jpeg"))
};
})
this is my image before rotate : before rotate and this is my image after rotate: after rotate after rotate background corners of image is black how to transparent? NOTE: I use this PNG for marker of google map. I read this posts :
Canvas fillStyle none in HTML5
Transparency context.fill style in canvas html5
thanks for helping.