szimek / signature_pad

HTML5 canvas based smooth signature drawing
http://szimek.github.io/signature_pad/
MIT License
10.91k stars 2.11k forks source link

Can fromDataURL and erase be used together? #775

Closed smalljop closed 4 months ago

smalljop commented 4 months ago

Can fromDataURL and erase be used together? Set compositeOperation to destination-out for erasing. After erasing, white lines will appear on the background image. How can I solve this problem? Thank you

smalljop commented 4 months ago

image

UziTech commented 4 months ago

Unfortunately html canvas doesn't have a concept of layers. So your background image could be drawn just like the signature and it wouldn't know the difference. In other words erasing will erase everything regardless of whether it is an image or not. And there is nothing we can do in signature_pad to change that.

One thing you can do is instead of adding the image to the canvas make the canvas background transparent and put the image behind it with position absolute or some other css.

smalljop commented 4 months ago

Thanks for your reply. If I set the image as the unit's label, then toDataURL will only have manually drawn content. If I want to get the image including the background, how can I do it?

UziTech commented 4 months ago

Once you have the final signature you can create a new canvas with the image and signature and get the full image that way

smalljop commented 4 months ago

Got it. Thank you.

smalljop commented 4 months ago

6