'When toDataURL, remove the background if globalCompositeOperation is used

I use the setBackgroundImage and globalCompositeOperation property to crop the canvas properly.

But when saving via toDataURL, I need to remove only the background, but so that all the objects that were cropped by globalCompositeOperation are preserved.

Now, if I delete or make the background transparent, then these actions also affect objects. How can this be circumvented?

I am using version 5.2.1



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source