Here is the image resizing routine the cart uses for generating thumbnails its in its third generation so if anyone has any suggestions how to improve it please post back:
public void ResizeImage(string originalName, string originalPath, string newPath, int NewWidth, int MaxHeight)
{
if (!System.IO.File.Exists(Server.MapPath(string.Concat(newPath, originalName))))
{
string ThumbFormat = Path.GetExtension(originalName);
System.Drawing.Image original = System.Drawing.Image.FromFile(Server.MapPath(string.Concat(originalPath, originalName)));
//Calculate thumb dimensions maintaining aspect ratio
if (original.Width <= NewWidth)
{
NewWidth = original.Width;
}
int NewHeight = original.Height * NewWidth / original.Width;
if (NewHeight > MaxHeight)
{
// Resize with height instead
NewWidth = original.Width * MaxHeight / original.Height;
NewHeight = MaxHeight;
}
System.Drawing.Image result = new Bitmap(NewWidth, NewHeight);
using (Graphics g = Graphics.FromImage(result))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
g.DrawImage(original, 0, 0, NewWidth, NewHeight);
using (System.IO.FileStream fs =
new System.IO.FileStream(Server.MapPath(string.Concat(string.Concat(newPath, originalName))), System.IO.FileMode.CreateNew, System.IO.FileAccess.Write))
{
switch (ThumbFormat.ToLower())
{
case ".gif":
result.Save(fs, System.Drawing.Imaging.ImageFormat.Gif);
break;
case ".jpg":
result.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
break;
case ".png":
result.Save(fs, System.Drawing.Imaging.ImageFormat.Png);
break;
}
}
}
}
}