mvc3 ImageResizer

廉价感情. 提交于 2019-12-20 07:15:03

问题


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);

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);

all that im trying to do is put the ImageBuilder inside the Path.Combine without getting an error, any help would be appreciated .


回答1:


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);


来源:https://stackoverflow.com/questions/14064563/mvc3-imageresizer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!