/// <summary> /// 将图片拷贝到上传目录中,并生成中、小缩略图 /// </summary> /// <param name="oPath">原始相对路径</param> /// <returns>返回图片名称,包括所在文件夹,比如 2009/9/28/1530703343314547.jpg</returns> public static string CopyToUploadPath(String oPath) { oPath = PathHelper.Map(oPath); // 需要保存的路径 String shortPath = Img.GetPhotoName(Path.GetExtension(oPath)); String targetPath = PathHelper.Map(strUtil.Join(sys.Path.DiskPhoto, shortPath)); logger.Info("copy pic. oPath=" + oPath + ", target=" + targetPath); // 1) 复制原图 file.Copy(oPath, targetPath); // 2) 生成最小缩略图 String sPath = Img.GetThumbPath(targetPath, ThumbnailType.Small); Img.SaveThumbnail(oPath, sPath, config.Instance.Site.PhotoThumbWidth, config.Instance.Site.PhotoThumbHeight, config.Instance.Site.GetPhotoThumbMode()); // 3) 生成中等缩略图 String mPath = Img.GetThumbPath(targetPath, ThumbnailType.Medium); Img.SaveThumbnail(oPath, mPath, config.Instance.Site.PhotoThumbWidthMedium, config.Instance.Site.PhotoThumbHeightMedium, SaveThumbnailMode.Auto); return(shortPath); }
/// <summary> /// 将图片拷贝到上传目录中,并生成中、小缩略图 /// </summary> /// <param name="oPath">原始相对路径</param> /// <returns>返回图片名称,包括所在文件夹,比如 2009/9/28/1530703343314547.jpg</returns> public static string CopyToUploadPath(String oPath) { oPath = PathHelper.Map(oPath); // 需要保存的路径 String shortPath = Img.GetPhotoName(Path.GetExtension(oPath)); String targetPath = PathHelper.Map(strUtil.Join(sys.Path.DiskPhoto, shortPath)); logger.Info("copy pic. oPath=" + oPath + ", target=" + targetPath); // 1) 复制原图 file.Copy(oPath, targetPath); Dictionary <String, ThumbInfo> thumbConfigMap = ThumbConfig.GetPhotoConfig(); foreach (KeyValuePair <String, ThumbInfo> kv in thumbConfigMap) { String sPath = Img.GetThumbPath(targetPath, kv.Key); Img.SaveThumbnail(oPath, sPath, kv.Value.Width, kv.Value.Height, kv.Value.Mode); } return(shortPath); }