Adding an invisible watermarks to SVG in C#?

26 views Asked by At

I found this discussion about images: Adding an invisible image watermark in C#?

And I've found some good open source libraries for watermarking raster images. One example: https://www.nuget.org/packages/Grizlah.Steganography.F5.StegSharp.Infrastructure

My interest is in watermarking SVG images. I know that different algorithms would be involved with vector.

1

There are 1 answers

0
Zeljko Predjeskovic On

If you have a library to manipulate svg, just add a similar group like that into the svg. Your could calculate the repition of the use elements by the width and height of the svg.

you can use svg dotnet nuget to do this.

 var sampleDoc = SvgDocument.Open<SvgDocument>("filePath")
 var waterMarkDoc = SvgDocument.FromSvg<SvgDocument>("<svg xmlns='http://www.w3.org/2000/svg' height='500px' width='500px' >
      <g>
        <text id="mark" transform="rotate(-45)" fill='rgba(45,45,45,0.3)' font-size='18'>
        watermark
        </text>
        <use href="#mark" x="100" y = "100"/>
        <use href="#mark" x="200" y = "100"/>
        <use href="#mark" x="300" y = "100"/>
        <use href="#mark" x="100" y = "200"/>
        <use href="#mark" x="200" y = "200"/>
        <use href="#mark" x="300" y = "200"/>
      </g>
 </svg>")
  foreach(var element in watermark.Children){
     sampleDoc.Children.Add(element);
  }


 sampleDoc.Draw().Save("filename.png"));

output