I am using CMS system for a website. My content contributor has put some very thick images into the system and then they have been converted into CMS so they are suitable for pages or articles. When the webular hits that page, they download the entire image, even if the contributor has resized the image. I've got an Image Resizer plugin, and what I want to do is add the width and height parameters to the name of the image name in the src name. One search seems to be that I should use the HTML Agility Pack to achieve this but someone can help me finish my code. Ive thought how to find IMG tags within content, but I do not know how to add SRC with width and height.
Old Tag The source value has changed for this notice This is my code so far. I need only if the statement states that if the img tag has width or height, then add them to the src attribute. .html try this:
& lt; Img src = "/ IMG_3556E__sq2.jpg? N = 9418" id = "/ IMG_3556E__sq2.jpg? N = 9418" width = "83px" height = "83px" />
& lt; Img src = "/ IMG_3556E__sq2.jpg width = 83 & amp;; amp; height = 83" id = "/ IMG_3556E__sq2.jpg? N = 9418" width = "83px" height = "83px" />
ContentManager contentManager = new ContentManager (); ContentData content = contentManager.GetItem (ID); HtmlDocument Doc = New HTML Document (); Doc.LoadHtml (Content.Html); In the foreach (doc.DocumentNode.SelectNodes, the HtmlNode node ("// img / @ src")) {if (// img is the width or height, this means the image has been resized) {// Attach which Nodes source within the content. Width = x & amp; Height = x}} Fixed zero main (string [] args) {var html.doc = new HtmlDocument (); HtmlDoc.Load (@ "E: \ Libs \ HtmlAgilityPack.1.4.0 \ htmldoc.html"); Foreach (HtmlNode node in htmlDoc.DocumentNode .SelectNodes ("// img [@src and (@with or @hite)]")) {var src = node.Attributes ["src"]. Value.Split ('?'); Var width = node.Attributes ["width"]. Value.Replace ("px", ""); Var height = node.Attributes ["height"]. Values. Change ("px", ""); Node .setitvitvalue ("src", src [0] + string.Format ("width = {0} and height {1}", width, height)); }}
Comments
Post a Comment