MVC3 ImageResizer [英] mvc3 ImageResizer
问题描述
我下载了纽金特ImageResizer和我试图调整对上传图片下面这个网页。的http:/ /imageresizing.net/docs/managed 但我不能看到把这个在瓦尔或图像变量,这样我就可以在 Path.Combine 这里是$ C $看看吧ç
I downloaded the Nugent ImageResizer and I am trying to resize a picture on upload following an example on this page http://imageresizing.net/docs/managed but I can't seen to put this in a Var or Image variable so i can see it in the Path.Combine here is the code
var fileName = Path.GetFileName(file.FileName);
var changename = getid + "_" + fileName;
ImageBuilder.Current.Build(changename, changename,
new ResizeSettings("width=130&height=130"));
var path = Path.Combine(Server.MapPath("~/uploads/profilepic"), changename);
file.SaveAs(path);
我怎样才能在 ImageBuilder VAR或某些类型的图像变什么,我想里面做的是这样的
How can I get the ImageBuilder inside a var or some type of image variable what i would like to do is something like this
var resized= ImageBuilder.Current.Build(changename, changename,
new ResizeSettings("width=130&height=130"));
var path = Path.Combine(Server.MapPath("~/uploads/profilepic"), resized);
file.SaveAs(path);
所有的即时通讯试图做的就是把在 ImageBuilder 在 Path.Combine 没有得到一个错误,任何帮助将是AP preciated。
all that im trying to do is put the ImageBuilder inside the Path.Combine without getting an error, any help would be appreciated .
推荐答案
ImageResizer支持的GUID和路径消毒。切勿使用上传的文件名按原样!
ImageResizer should be given the uploaded file and the output path directly
ImageResizer supports both GUIDs and path sanitization. NEVER use the uploaded filename as-is!
var i = new ImageJob(file,
"~/uploads/profilepic/<guid>_<filename:A-Za-z0-9>.<ext>",
new ResizeSettings("width=130&height=130&format=jpg"));
i.CreateParentDirectory = true; //Auto-create the uploads directory.
i.Build();
var newVirtualPath = ImageResizer.Util.PathUtils.GuessVirtualPath(i.FinalPath);
这篇关于MVC3 ImageResizer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!