private void testConfigString(String cfgString) { Dictionary <String, ThumbInfo> cfgList = ThumbConfig.ReadString(cfgString); Assert.AreEqual(4, cfgList.Count); ThumbInfo x = cfgList["s"]; Assert.AreEqual(75, x.Width); Assert.AreEqual(75, x.Height); Assert.AreEqual(SaveThumbnailMode.Auto, x.Mode); x = cfgList["sx"]; Assert.AreEqual(200, x.Width); Assert.AreEqual(200, x.Height); Assert.AreEqual(SaveThumbnailMode.Auto, x.Mode); x = cfgList["m"]; Assert.AreEqual(600, x.Width); Assert.AreEqual(600, x.Height); Assert.AreEqual(SaveThumbnailMode.Auto, x.Mode); x = cfgList["b"]; Assert.AreEqual(1024, x.Width); Assert.AreEqual(1024, x.Height); Assert.AreEqual(SaveThumbnailMode.Auto, x.Mode); }
// 保存图片大小等信息 private void updatePhotoSize(PhotoPost post) { String photoPath = post.DataUrl; Dictionary <String, PhotoInfo> dic = new Dictionary <String, PhotoInfo>(); foreach (KeyValuePair <String, ThumbInfo> kv in ThumbConfig.GetPhotoConfig()) { String xpath = Img.GetThumbPath(strUtil.Join(sys.Path.DiskPhoto, photoPath), kv.Key); String thumbPath = PathHelper.Map(xpath); if (file.Exists(thumbPath) == false) { continue; } Size size = Img.GetPhotoSize(thumbPath); dic.Add(kv.Key, new PhotoInfo { Width = size.Width, Height = size.Height }); } String str = ObjectContext.Create <PhotoInfoHelper>().ConvertString(dic); if (strUtil.IsNullOrEmpty(str)) { return; } post.SizeInfo = str; post.update(); log("重新统计成功=" + post.Id + ",path=" + photoPath); }
private void makeUserFace(Object objParam) { List <User> userList = getUsersById(objParam as ThumbParam); foreach (User user in userList) { lastId = user.Id; // 循环生成所有缩略图 foreach (KeyValuePair <String, ThumbInfo> kv in ThumbConfig.GetAvatarConfig()) { String srcPath = getFaceSrcPath(user.Pic); if (file.Exists(srcPath) == false) { log("pic original not exist=" + srcPath); continue; } log("begin make " + kv.Key + "=>" + srcPath); AvatarUploader.SaveThumbSingle(srcPath, kv.Key, kv.Value); } } log("操作结束, last user id=" + lastId); }
private static int getCfgWidth() { ThumbInfo t = ThumbConfig.GetPhoto("sx"); if (t == null) { return(170); } return(t.Width); }
private static Boolean saveAvatarThumb(String srcPath) { Dictionary <String, ThumbInfo> dicThumbConfig = ThumbConfig.GetAvatarConfig(); foreach (KeyValuePair <String, ThumbInfo> kv in dicThumbConfig) { SaveThumbSingle(srcPath, kv.Key, kv.Value); } return(true); }
public Dictionary <String, ThumbInfo> GetAvatarThumbConfig() { if (_avatarThumbConfig == null) { // 默认值 if (strUtil.IsNullOrEmpty(this.AvatarThumb)) { this.AvatarThumb = "s=width:48|height:48|mode:cut, m=width:100|height:100|mode:cut, b=width:200|height:200|mode:cut"; } _avatarThumbConfig = ThumbConfig.ReadString(this.AvatarThumb); } return(_avatarThumbConfig); }
public Dictionary <String, ThumbInfo> GetPhotoThumbConfig() { if (_photoThumbConfig == null) { // 默认值 if (strUtil.IsNullOrEmpty(this.PhotoThumb)) { this.PhotoThumb = "s=width:170|height:170|mode:cut, m=width:600|height:600|mode:auto, b=width:1024|height:1024|mode:auto"; } _photoThumbConfig = ThumbConfig.ReadString(this.PhotoThumb); } return(_photoThumbConfig); }
public static void Delete(String picPath) { String fullPath = strUtil.Join("/static/upload/", picPath); String oPath = Img.GetOriginalPath(fullPath); deleteImgPrivate(oPath, "original"); Dictionary <String, ThumbInfo> dicThumbConfig = ThumbConfig.GetAvatarConfig(); foreach (KeyValuePair <String, ThumbInfo> kv in dicThumbConfig) { String mPath = Img.GetThumbPath(fullPath, kv.Key); deleteImgPrivate(mPath, kv.Key); } }
// 保存图片大小等信息 private void updatePhotoSize(PhotoPost post) { String photoPath = post.DataUrl; if (strUtil.IsNullOrEmpty(photoPath)) { return; } if (photoPath.ToLower().StartsWith("http://")) { return; } if (photoPath.StartsWith("/")) { return; } Dictionary <String, PhotoInfo> dic = new Dictionary <String, PhotoInfo>(); foreach (KeyValuePair <String, ThumbInfo> kv in ThumbConfig.GetPhotoConfig()) { String xpath = Img.GetThumbPath(strUtil.Join(sys.Path.DiskPhoto, photoPath), kv.Key); String thumbPath = PathHelper.Map(xpath); Size size = Img.GetPhotoSize(thumbPath); dic.Add(kv.Key, new PhotoInfo { Width = size.Width, Height = size.Height }); } String str = ObjectContext.Create <PhotoInfoHelper>().ConvertString(dic); if (strUtil.IsNullOrEmpty(str)) { return; } post.SizeInfo = str; post.update(); }
private void makeThumbPrivate(String photoPath) { // 循环生成所有缩略图 foreach (KeyValuePair <String, ThumbInfo> kv in ThumbConfig.GetPhotoConfig()) { String srcPath = getPhotoSrcPath(photoPath); if (file.Exists(srcPath) == false) { logError("pic original not exist=" + srcPath); continue; } log("begin make " + kv.Key + "=>" + srcPath); try { Uploader.SaveThumbSingle(srcPath, kv.Key, kv.Value); } catch (Exception ex) { logError("error=>" + ex.Message); } } }
public void testThumbConfig() { String cfgString = "s=width:75|height:75|mode:auto, sx=width:200|height:200|mode:auto, m=width:600|height:600|mode:auto, b=width:1024|height:1024|mode:auto"; testConfigString(cfgString); // 加上多余空格 cfgString = " s=width:75|height:75|mode:auto, sx=width:200|height:200|mode:auto, m=width:600|height:600|mode:auto, b=width:1024|height:1024|mode:auto "; testConfigString(cfgString); // 加上大小写 cfgString = " s = width:75 | HeiGht:75 | mode:auto, SX=width:200|height:200|mode:auto, m=width : 600 |height:600| Mode : auto, b = width:1024 | height:1024| mode:auto "; testConfigString(cfgString); // 边界测试 cfgString = " "; Dictionary <String, ThumbInfo> cfgList = ThumbConfig.ReadString(cfgString); Assert.AreEqual(0, cfgList.Count); cfgString = null; cfgList = ThumbConfig.ReadString(cfgString); Assert.AreEqual(0, cfgList.Count); cfgString = " aaaaaaaaaaaaa, SX=width:200|height:200|mode:auto, m=width : 600 |height:600| Mode : cut, o "; cfgList = ThumbConfig.ReadString(cfgString); Assert.AreEqual(2, cfgList.Count); ThumbInfo x = cfgList["sx"]; Assert.AreEqual(200, x.Width); Assert.AreEqual(200, x.Height); Assert.AreEqual(SaveThumbnailMode.Auto, x.Mode); x = cfgList["m"]; Assert.AreEqual(600, x.Width); Assert.AreEqual(600, x.Height); Assert.AreEqual(SaveThumbnailMode.Cut, x.Mode); }
public Thumb(ThumbConfig config){}
/// <summary> /// 保存上传的图片 /// </summary> /// <param name="postedFile"></param> /// <returns></returns> public static Result SaveImg(HttpFile postedFile) { return(SaveImg(postedFile, ThumbConfig.GetPhotoConfig())); }