Exemple #1
0
        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);
        }
Exemple #2
0
        // 保存图片大小等信息
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        private static int getCfgWidth()
        {
            ThumbInfo t = ThumbConfig.GetPhoto("sx");

            if (t == null)
            {
                return(170);
            }
            return(t.Width);
        }
Exemple #5
0
        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);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
            }
        }
Exemple #9
0
        // 保存图片大小等信息
        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();
        }
Exemple #10
0
        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);
                }
            }
        }
Exemple #11
0
        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){}
Exemple #13
0
 /// <summary>
 /// 保存上传的图片
 /// </summary>
 /// <param name="postedFile"></param>
 /// <returns></returns>
 public static Result SaveImg(HttpFile postedFile)
 {
     return(SaveImg(postedFile, ThumbConfig.GetPhotoConfig()));
 }