Skip to content

Instantly share code, notes, and snippets.

@cloudcreatordotio
cloudcreatordotio / ImageUtil.cs
Created April 19, 2024 11:59 — forked from gsscoder/ImageUtil.cs
C# image utilities
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
public static class ImageUtil
{
public static Image Resize(this Image image, int width, int height)
{
var destRect = new Rectangle(0, 0, width, height);
public static class HtmlTruncator
{
public static string LimitOnWordBoundary(string str, int maxLength, string ellipses = "...")
{
XmlDocument doc = new XmlDocument();
XmlParserContext context = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), null, XmlSpace.Preserve);
XmlTextReader reader = new XmlTextReader("<xml>" + str + "</xml>", XmlNodeType.Document, context);
bool shouldWriteEllipses;