Exemple #1
0
        /// <summary>
        /// URL拼接
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="urlparameter">参数,用分号隔开(';')</param>
        /// <param name="Path">路径</param>
        /// <returns></returns>
        public static string UrlConverter(string filename, string urlparameter, string Path, bool IsUrlRewriter = true)
        {
            string        result  = string.Empty;        //返回拼接结果
            StringBuilder Urlpar  = new StringBuilder(); //URL参数连接
            string        Urlpars = string.Empty;        //URL参数
            StringBuilder query   = new StringBuilder();

            string[] ar = new string[] { "usage", "metal", "style", "cash", "sort", "od", "size", "weight" };
            if (!string.IsNullOrEmpty(urlparameter))
            {
                string[] Par = urlparameter.Split(';');
                for (int i = 0; i < Par.Length; i++)
                {
                    if (Par[i].Trim() != string.Empty)
                    {
                        if (Par[i].IndexOf('=') > -1)
                        {
                            string[] ParVa = Par[i].Split('=');
                            string   key   = ParVa[0].ToLower();
                            if (key == "nodeid")
                            {
                                Urlpar.Append("-c" + ParVa[1]);
                            }
                            else if (key.In(ar))
                            {
                                if (query.ToString().IndexOf("?") == -1)
                                {
                                    query.Append("?" + ParVa[0] + "=" + ParVa[1]);
                                }
                                else
                                {
                                    query.Append("&" + ParVa[0] + "=" + ParVa[1]);
                                }
                            }
                            else
                            {
                                Urlpar.Append("-" + ParVa[1]);
                            }
                        }
                    }
                }
                Urlpars = urlparameter.Replace(";", "&");
            }

            string DummyPath = "/" + Path;
            string UrlModel  = ConfigManager.GetString("UrlModel");
            string UrlExt    = ConfigManager.GetString("UrlExt");

            if (UrlModel == "0" || !IsUrlRewriter)
            {
                //动态
                if (!string.IsNullOrEmpty(Urlpars))
                {
                    result = DummyPath + filename + ".aspx?" + Urlpars;
                }
                else
                {
                    result = DummyPath + filename + ".aspx";
                }
            }
            else
            {
                //伪静态
                if (!string.IsNullOrEmpty(Urlpar.ToString()))
                {
                    result = DummyPath + filename + Urlpar.ToString() + UrlExt + query;
                }
                else
                {
                    result = DummyPath + filename + UrlExt;
                }
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 生成图片水印和缩略图
        /// </summary>
        /// <param name="hpf">客户端上传文件</param>
        /// <param name="sourcePath">文件原图存放路径</param>
        /// <param name="ThumbPath">文件缩略图存放路径</param>
        /// <param name="textWatermarkPath">服务器端文字水印图存放路径(文字水印)</param>
        /// <param name="imageWatermarkPath">服务器端图片水印图存放路径(图片水印)</param>
        /// <param name="waterCharater">水印文字</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="pointX">原始图片水印的X坐标</param>
        /// <param name="pointY">原始图片水印的Y坐标</param>
        /// <param name="enableImageWatermark">是否生成图片水印</param>
        /// <param name="enableCharacterWatermark">是否生成文字水印</param>
        /// <param name="isMakeThumbnail">是否生成缩略图</param>
        /// <returns></returns>
        public static string GenerateImageWithWater(HttpPostedFile hpf, string sourcePath, string ThumbPath, string textWatermarkPath,
                                                    string imageWatermarkPath, string waterCharater, int width, int height, int pointX, int pointY, bool enableImageWatermark,
                                                    bool enableCharacterWatermark, bool isMakeThumbnail)
        {
            if (hpf.ContentLength > 0)
            {
                string fileContentType = hpf.ContentType;
                if (ExtensionValidator(fileContentType, 1))
                {
                    #region 初始化变量
                    string   name     = hpf.FileName;// 客户端文件路径
                    string   randName = DateTime.Now.ToString("yyyyMMddHHmmssfffffff");
                    FileInfo file     = new FileInfo(name);
                    string   fileName = randName + file.Name;      // 文件名称

                    string source         = sourcePath + fileName; // 原图片存放路径
                    string thumb          = ThumbPath + fileName;  // 服务器端缩略图存放路径
                    string TextWatermark  = textWatermarkPath;     // 服务器端文字水印图存放路径
                    string ImageWatermark = imageWatermarkPath;    //服务器端图片水印图存放路径

                    string webFilePath                = HttpContext.Current.Server.MapPath(source);
                    string webFilePath_Thumb          = HttpContext.Current.Server.MapPath(thumb);
                    string webFilePath_TextWatermark  = HttpContext.Current.Server.MapPath(TextWatermark);
                    string webFilePath_ImageWatermark = HttpContext.Current.Server.MapPath(ImageWatermark);
                    string webFilePath_Temp           = HttpContext.Current.Server.MapPath(ConfigManager.GetString("TempFolder") + fileName);//服务器端水印图路径(图片)
                    #endregion

                    #region 原始图片加水印
                    ImageHelper helper = new ImageHelper();
                    helper.ImageDeaphaneity       = 1F;
                    helper.SaveWaterMarkImagePath = sourcePath.Replace("~/", "");
                    helper.SourceImagePath        = name;
                    helper.WaterMarkImagePath     = "UploadFiles/Product/watermark.gif";
                    helper.ToWaterMark(fileName, pointX, pointY); //保存原图片并加水印
                    #endregion

                    #region 生成缩略图
                    if (isMakeThumbnail)
                    {
                        MakeThumbnail(name, webFilePath_Temp, width, height);
                    }
                    #endregion

                    #region 文字水印
                    //int x, y;
                    //if (enableCharacterWatermark)
                    //{
                    //    GetWaterMarkPosition(imgAlign, out x, out y, width, height, 100, 100);
                    //    AddWater(webFilePath, webFilePath_TextWatermark, waterCharater, x, y);//添加文字水印
                    //}
                    #endregion

                    #region 缩略图加水印
                    if (enableImageWatermark)
                    {
                        int   thumbX, thumbY;
                        Image ImgSource = Image.FromFile(webFilePath);                                 //原始图
                        Image ImgThumb  = Image.FromFile(webFilePath_Temp);                            //缩略图
                        int   Multiple  = (int)Math.Ceiling((double)ImgSource.Width / ImgThumb.Width); //比率倍数
                        thumbX = pointX / Multiple;                                                    //缩略图水印X坐标
                        thumbY = pointY / Multiple;                                                    //缩略图水印Y坐标
                        helper.ImageDeaphaneity       = 1F;
                        helper.SaveWaterMarkImagePath = ThumbPath.Replace("~/", "");
                        helper.SourceImagePath        = webFilePath_Temp;
                        helper.WaterMarkImagePath     = "UploadFiles/Product/watermark.gif";
                        helper.ToWaterMark(fileName, 10, 10); //保存原图片并加水印
                    }
                    #endregion
                    return(source + "|" + thumb + "|" + TextWatermark + "|" + ImageWatermark);
                }
                else
                {
                    return("图片格式必须为[" + MimeDict.Keys.ExpandAndToString(",") + "]");
                }
            }
            else
            {
                return("请选择要上传的产品!");
            }
        }