How to Add a Watermark to Your Website with HTML Canvas

Web watermark generation solutionsWatermark generation via canvasCanvas compatibilityHere we use canvas to generate base64 images and check compatibility through CanIUse website, if used in mobile as well as some management systems, compatibility issue…


This content originally appeared on Level Up Coding - Medium and was authored by Maxwell

Web watermark generation solutions

Watermark generation via canvas

Canvas compatibility

Here we use canvas to generate base64 images and check compatibility through CanIUse website, if used in mobile as well as some management systems, compatibility issues can be completely ignored.

The HTMLCanvasElement.toDataURL method returns a data URI containing a display of the image. You can use the type parameter for its type, which defaults to PNG format. The resolution of the image is 96dpi.
If the height or width of the canvas is 0, then the string “data:,” is returned. If the incoming type is not “image/png”, but the returned value starts with “data:image/png”, then the incoming type is not supported.

The specific code implementation is as follows:

The effect is as follows:

Watermark generation via SVG

SVG: (Scalable Vector Graphics) is a graphics format for describing two-dimensional vector graphics based on Extensible Markup Language (XML). SVG was developed by the W3C and is an open standard.

SVG browser compatibility

Compared to Canvas, SVG has better browser compatibility, and the way to generate watermarks using SVG is similar to that of Canvas, except that the base64Url generation method is replaced with SVG. as follows:

The effect is as follows:

Summary

Security issues can not be careless, for some sensitive web page, we can add a watermark to the viewer to warn the role of reducing the leak, even if the leak, it is possible to track the leaker.

If you are interested in my articles, you can follow me on Medium or Twitter.


How to Add a Watermark to Your Website with HTML Canvas was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Level Up Coding - Medium and was authored by Maxwell


Print Share Comment Cite Upload Translate Updates
APA

Maxwell | Sciencx (2022-11-17T21:49:05+00:00) How to Add a Watermark to Your Website with HTML Canvas. Retrieved from https://www.scien.cx/2022/11/17/how-to-add-a-watermark-to-your-website-with-html-canvas/

MLA
" » How to Add a Watermark to Your Website with HTML Canvas." Maxwell | Sciencx - Thursday November 17, 2022, https://www.scien.cx/2022/11/17/how-to-add-a-watermark-to-your-website-with-html-canvas/
HARVARD
Maxwell | Sciencx Thursday November 17, 2022 » How to Add a Watermark to Your Website with HTML Canvas., viewed ,<https://www.scien.cx/2022/11/17/how-to-add-a-watermark-to-your-website-with-html-canvas/>
VANCOUVER
Maxwell | Sciencx - » How to Add a Watermark to Your Website with HTML Canvas. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/17/how-to-add-a-watermark-to-your-website-with-html-canvas/
CHICAGO
" » How to Add a Watermark to Your Website with HTML Canvas." Maxwell | Sciencx - Accessed . https://www.scien.cx/2022/11/17/how-to-add-a-watermark-to-your-website-with-html-canvas/
IEEE
" » How to Add a Watermark to Your Website with HTML Canvas." Maxwell | Sciencx [Online]. Available: https://www.scien.cx/2022/11/17/how-to-add-a-watermark-to-your-website-with-html-canvas/. [Accessed: ]
rf:citation
» How to Add a Watermark to Your Website with HTML Canvas | Maxwell | Sciencx | https://www.scien.cx/2022/11/17/how-to-add-a-watermark-to-your-website-with-html-canvas/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.