BetterCms.Module.MediaManager.Services.DefaultMediaImageService.CreateSvgThumbnail C# (CSharp) Method

CreateSvgThumbnail() private method

private CreateSvgThumbnail ( Stream sourceStream, Stream destinationStream, Size size ) : void
sourceStream Stream
destinationStream Stream
size System.Drawing.Size
return void
        private void CreateSvgThumbnail(Stream sourceStream, Stream destinationStream, Size size)
        {
            sourceStream.Seek(0, SeekOrigin.Begin);
            var xDocument = XDocument.Load(sourceStream);
            var root = xDocument.Root;
            if (root == null || root.Name.LocalName != "svg")
            {
                const string message = "An error has occured while trying to read the file";
                throw new ValidationException(() => message, message);
            }
            var attributes = root.Attributes().ToList();

            var widthAttribute = attributes.FirstOrDefault(x => x.Name == "width");
            if (widthAttribute == null)
            {
                widthAttribute = new XAttribute("width", size.Width.ToString());
                attributes.Add(widthAttribute);
            }
            else
            {
                widthAttribute.Value = size.Width.ToString();
            }
            var heightAttribute = attributes.FirstOrDefault(x => x.Name == "height");
            if (heightAttribute == null)
            {
                heightAttribute = new XAttribute("height", size.Height.ToString());
                attributes.Add(heightAttribute);
            }
            else
            {
                heightAttribute.Value = size.Height.ToString();
            }
            root.ReplaceAttributes(attributes);
            xDocument.Save(destinationStream);
        }