Lorna70
asked on
Image resizer required
I already have some code to resize images but it's very clunky and I'm sure it could be written better - e.g it saves the image to the server, then resizes, then deletes the original image. This has worked fine on sites where only one admin person is uploading images but I'm now starting a project which may potentially have hundreds of users uploading at once. I need advice and was wondering if anyone could recommend something they've used for a site with hundreds of people uploading concurrently which has been successful?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry Kaufmed - I've re-read your link and it does show how to resize without first saving to disc. Many thanks :-)
ASKER
public void Upload(Object s, EventArgs e)
{
int picID = 0;
//get userid from session
int userId = 1;
int photoCatId = 0;
string strCaption = "";
string strDesc = "";
//first check if data entry is valid
if (Page.IsValid)
{
string newFileName = "";
HttpPostedFile postedFile = FileUpload.PostedFile;
if (IsImageValid(FileUpload.P
{
filename = Path.GetFileName(postedFil
//Path where file will be uploaded
string pathToFile = Server.MapPath("../uploade
filename = getUniqueFilename();
string fullPath = pathToFile + "\\" + filename;
postedFile.SaveAs(fullPath
//now resize photo
Response.ContentType = "image/jpeg";
ResizeImage o = new ResizeImage();
// Load your image and resize to 500
o.File = fullPath;
o.Width = 500;
o.UsePercentages = false;
//use next line to print to screen without saving
//o.GetThumbnail().Save(Re
newFileName = picID + ".jpg";
string newFilePath = pathToFile + "\\" + newFileName;
o.GetThumbnail().Save(newF
//Now resize to 100
o.Height = 100;
o.Width = 0;
o.UsePercentages = false;
o.PreserveAspectRatio = true;
newFileName = picID + "-s.jpg";
newFilePath = pathToFile + "\\" + newFileName;
o.GetThumbnail().Save(newF
//now delete original large image
System.IO.File.Delete(full
string strURL = "add_new_pics.aspx";
Response.Redirect(strURL, false);
}
else
{
lblWarnings.Text = "<font color='red'>Error - please check your image name (no spaces) and size (max width/height = 4000px)</font>";
}
}
}
I've attached another file which has the ResizeImage class code.
resizeImageClass.txt