Web Design Nottingham Header

Freetextbox image upload

Publication Date: Thu 19 Jun 2008

We have utilised freetextbox as a tool for our bespoke content management systems for a number of years now.

One issue we had involved the image gallery control that enables you to upload images to the server and reference them in freetextbox, it does not physically resize the image. This meant that novice users would sometimes upload 2MB images and the resulting page that was displayed took a long time to download the images.

Thankfully we found an alternative image upload component on the freetextbox forum that allows the user to specify the size of the image and the control will resize the physical image.

This was good but the resize wasn't done using a good interpolation mode which results in poor quality images like this:

clip_image002.jpg

Therefore, we altered the source code to resize the image using High Quality Bicubic interpolation, which produces better quality like this:

clip_image002s3.jpg

We also only allow the user to specify a width or height for the image as the resultant image should retain the aspect ratio. The code below does the resizing. I will upload all the files in a few days.

Note there seems to be a bug with the high quality bicubic resize as it leaves a black line on the top and left of the resultant image, I got around this by starting at -1,-1 on the redraw (System.Drawing.Rectangle(-1, -1, width + 1, destHeight + 1)).

private System.Drawing.Bitmap MakeImage(System.Drawing.Bitmap bmOrig, int width, string savePath)
{

int destHeight = bmOrig.Height * width / bmOrig.Width;

System.Drawing.Bitmap bm = new System.Drawing.Bitmap(width, destHeight,

System.Drawing.Imaging.PixelFormat.Format24bppRgb);

bm.SetResolution(bmOrig.HorizontalResolution,

bmOrig.VerticalResolution);

System.Drawing.Graphics grPhoto = System.Drawing.Graphics.FromImage(bm);

grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

grPhoto.DrawImage(bmOrig,

new System.Drawing.Rectangle(-1, -1, width + 1, destHeight + 1),

new System.Drawing.Rectangle(0, 0, bmOrig.Width, bmOrig.Height),

System.Drawing.GraphicsUnit.Pixel);

grPhoto.Dispose();

bm.Save(savePath);

return bm;

}

Quotes

"Excellent system, has saved my department lots of time, looks professional."
Gedling Dental Lab

Latest Projects

Angel Wings web design Labarde web design Internet Gardener web design Stonesilver web design Build Investment Jewellery web design

Developer Certifications

MCPD logo

Partners

Comodo logo protx logo

Coding Standards

XHTML CSS

Agilis Software Limited | 2 Lynemouth Court, Arnold, Nottingham. NG5 8TY
Registered in England No. 5688723. VAT No. 886 4538 70
Tel: 07973 766989
Email: stephen@agilissoftware.co.uk