Example #1
0
        public void ProcessRequest(HttpContext context)
        {
            if (context.Request.Files == null || context.Request.Files.Count == 0)
            {
                var errResult = new
                {
                    Result = false,
                };

                context.Response.Write(JsonConvert.SerializeObject(errResult));
                return;
            }

            HttpPostedFile hp       = context.Request.Files[0];
            string         waring   = ""; //上传警告信息
            string         savepath = ImageDealLib.uploadbystream(hp.InputStream, "/UploadImages/", out waring);



            List <UploadImageResult> uploadResult = new List <UploadImageResult>();

            uploadResult.Add(new UploadImageResult()
            {
                path = savepath, name = hp.FileName, size = hp.ContentLength
            });

            context.Response.Write(JsonConvert.SerializeObject(uploadResult));
        }
Example #2
0
        public System.Drawing.Image AddFontWater(string vpath)
        {
            //string json = "{text:\"水印文字\",family: \"Arial\", size: \"18pt\", weight: \"bold\", style: \"normal\", decoration: \"line-through\",color:\"rgb(255, 51, 153)\", background: \"rgb(204,153,102)\" }";
            string    json  = Request.Form["fontmodel"];
            FontModel model = JsonConvert.DeserializeObject <FontModel>(json);

            return(ImageDealLib.ConverFontToImg(vpath, model));
        }
        public void ProcessRequest(HttpContext context)
        {
            HttpPostedFile hp       = context.Request.Files["pic"];
            string         waring   = ""; //上传警告信息
            string         savepath = ImageDealLib.uploadbystream(hp.InputStream, "/UploadImages/", out waring);

            context.Response.Write(savepath);
        }
        public void ProcessRequest(HttpContext context)
        {
            string picpath   = context.Request["picpath"];
            string warning   = "";
            string suoluepic = ImageDealLib.Resizepic(picpath, ImageDealLib.ResizeType.XY, "/UploadImages/", ImageDealLib.ImageType.JPEG, 48, 48, ImageDealLib.FileCache.Save, out warning);

            context.Response.Write(suoluepic);
        }
Example #5
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (function.isAjax())
     {
         string result = "";
         try
         {
             string action  = Request["action"];
             string vpath   = ImgPath;
             string warning = "";
             double percent = Convert.ToDouble(Request["percent"]);
             if (action.Equals("crop"))
             {
                 double x1     = double.Parse(Request.Form["x1"]);
                 double y1     = double.Parse(Request.Form["y1"]);
                 double width  = double.Parse(Request.Form["width"]);
                 double height = double.Parse(Request.Form["height"]);
                 x1        = x1 / percent; y1 = y1 / percent;
                 width     = width / percent; height = height / percent;
                 savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                 result    = ImageDealLib.imgcrop(vpath, savePath, (int)x1, (int)y1, (int)width, (int)height, ImageDealLib.FileCache.Save, out warning);
             }
         }
         catch (Exception ex) { result = ex.Message; }
         Response.Clear(); Response.Write(result); Response.Flush(); Response.End();
     }
     if (!IsPostBack)
     {
         if (!Directory.Exists(Server.MapPath(savePath)))
         {
             Directory.CreateDirectory(Server.MapPath(savePath));
         }
         if (string.IsNullOrEmpty(IPath))
         {
             function.WriteErrMsg("未指定图片路径");
         }
         using (FileStream fs = new FileStream(Server.MapPath(ImgPath), FileMode.Open, FileAccess.Read))
         {
             System.Drawing.Image img = System.Drawing.Image.FromStream(fs);
             //1,首先将图片强制压缩为760的宽
             //2,将比率交与前端,前端等比缩小裁剪框(1920*650)
             if (img.Width < 1920 || img.Height < 650)
             {
                 function.Script(this, "minImgAlert();");
             }
             ImgPercent = (double)760 / (double)img.Width;
             int width  = (int)(img.Width * ImgPercent);
             int height = (int)(img.Height * ImgPercent);
             img.Dispose();
             Bitmap bmp   = imghelp.ZoomImg(ImgPath, height, width);
             string vpath = savePath + function.GetRandomString(6) + ".jpg";
             imghelp.SaveImg(vpath, bmp);
             photo_img.Src = vpath;
         }
     }
 }
Example #6
0
        public void ProcessRequest(HttpContext context)
        {
            int    x1      = int.Parse(context.Request["x1"]);
            int    y1      = int.Parse(context.Request["y1"]);
            int    width   = int.Parse(context.Request["width"]);
            int    height  = int.Parse(context.Request["height"]);
            string picpath = context.Request["picpath"];
            string warning = "";  //剪辑警告信息
            string d       = ImageDealLib.imgcrop(picpath, "/UploadImages/", x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);

            context.Response.Write(d);
        }
        //{"x":80.00000000000006,"y":76.50000000000001,"width":480,"height":855.0000000000001,"rotate":0,"scaleX":1,"scaleY":1}
        //其提交的数值是经过计算后还原的实际值,所以不需要再计算宽高比率.
        protected void Cut_Btn_Click(object sender, EventArgs e)
        {
            if (!Directory.Exists(Server.MapPath(savePath)))
            {
                Directory.CreateDirectory(Server.MapPath(savePath));
            }
            //图片是50%压缩的,所以宽高都需要处理,然后再执行裁剪方法
            JObject jobj    = JsonConvert.DeserializeObject <JObject>(Cut_Hid.Value);
            string  warning = "";
            string  result  = ImageDealLib.imgcrop(Url, savePath + "123.jpg", (int)jobj["x"], (int)jobj["y"], (int)jobj["width"], (int)jobj["height"], ImageDealLib.FileCache.Save, out warning);

            function.Script(this, "top.diy_bk.setbk('" + result + "');");
        }
        public void ProcessRequest(HttpContext context)
        {
            string picpath  = context.Request["picpath"];
            string warning  = "";
            string waterpic = ImageDealLib.makewatermark(
                picpath,
                "/UploadImages/dolphin48.png",
                ImageDealLib.WaterType.RightDown,
                "/UploadImages/",
                ImageDealLib.ImageType.JPEG,
                ImageDealLib.FileCache.Save,
                out warning);

            context.Response.Write(waterpic);
        }
Example #9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (function.isAjax())
     {
         string action  = Request["action"];
         string vpath   = Request["vpath"];
         string warning = "";
         string result  = "";
         if (action.Equals("crop"))
         {
             int x1     = int.Parse(Request.Form["x1"]);
             int y1     = int.Parse(Request.Form["y1"]);
             int width  = int.Parse(Request.Form["width"]);
             int height = int.Parse(Request.Form["height"]);
             savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
             result    = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);
         }
         Response.Clear(); Response.Write(result); Response.Flush(); Response.End();
     }
     if (!IsPostBack)
     {
         if (!Directory.Exists(Server.MapPath(savePath)))
         {
             Directory.CreateDirectory(Server.MapPath(savePath));
         }
         if (string.IsNullOrEmpty(IPath))
         {
             function.WriteErrMsg("未指定图片路径");
         }
         using (FileStream fs = new FileStream(Server.MapPath(ImgPath), FileMode.Open, FileAccess.Read))
         {
             System.Drawing.Image image = System.Drawing.Image.FromStream(fs);
             int width  = image.Width;
             int height = image.Height;
             wrap_div.Style.Add("width", width + "px");
             wrap_div.Style.Add("height", height + "px");
         }
     }
 }
Example #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (B_Admin.GetLogin() == null)
            {
                B_User.CheckIsLogged();
            }
            else
            {
                B_Admin.CheckIsLogged();
            }
            if (function.isAjax())
            {
                string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径
                if (vpath.Contains("?"))
                {
                    vpath = vpath.Substring(0, vpath.IndexOf("?"));
                }
                switch (action)
                {
                case "crop":    //根据提交的图片路径与宽度等参数,完成剪切
                {
                    int x1     = int.Parse(Request.Form["x1"]);
                    int y1     = int.Parse(Request.Form["y1"]);
                    int width  = int.Parse(Request.Form["width"]);
                    int height = int.Parse(Request.Form["height"]);
                    savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                    result    = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);
                }
                break;

                case "rotate":
                {
                    int    angle = DataConverter.CLng(Request.Form["angle"]);
                    Bitmap bmp   = imgHelper.Rotate(vpath, angle);
                    savePath += function.GetRandomString(6) + Path.GetExtension(vpath);
                    result    = imgHelper.SaveImg(savePath, bmp);
                    bmp.Dispose();
                }
                break;

                case "zoom":    //缩放
                {
                    int width  = int.Parse(Request.Form["width"]);
                    int height = int.Parse(Request.Form["height"]);
                    savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                    Bitmap bmp = imgHelper.ZoomImg(vpath, height, width);
                    result = imgHelper.SaveImg(savePath, bmp);
                }
                break;

                case "fontwater":    //文字水印
                {
                    System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg");
                    savePath += "fontw_" + Path.GetFileName(vpath);
                    result    = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
                    result   += "?" + function.GetRandomString(6);
                }
                break;

                case "imgwater":    //水印图片路径
                {
                    string watervpath = Request.Form["watervpath"];
                    int    trans      = DataConverter.CLng(Request.Form["trans"]);
                    savePath += "imgw_" + Path.GetFileName(vpath);
                    result    = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans);
                    result   += "?" + function.GetRandomString(6);
                }
                break;
                }
                Response.Write(result); Response.Flush(); Response.End();
            }
            if (!IsPostBack)
            {
                if (string.IsNullOrEmpty(IPath) || !SafeC.IsImage(IPath))
                {
                    function.WriteErrMsg("只允许编辑图片文件!");
                }
                if (!Directory.Exists(Server.MapPath(savePath)))
                {
                    Directory.CreateDirectory(Server.MapPath(savePath));
                }
                if (!File.Exists(Server.MapPath(IPath)))
                {
                    function.WriteErrMsg("需要修改的图片" + IPath + "不存在");
                }
                NowImg_Hid.Value = SourceImg_Hid.Value = IPath;
                System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(IPath));
                ImgWidth_Hid.Value  = img.Width.ToString();
                ImgHeight_Hid.Value = img.Height.ToString();
                RPT.DataSource      = GetWaterImgDT();
                RPT.DataBind();
                img.Dispose();
            }
        }
Example #11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        buser.CheckIsLogin();
        if (function.isAjax())
        {
            string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径
            if (vpath.Contains("?"))
            {
                vpath = vpath.Substring(0, vpath.IndexOf("?"));
            }
            switch (action)
            {
            case "crop":    //根据提交的图片路径与宽度等参数,完成剪切
            {
                int x1     = int.Parse(Request.Form["x1"]);
                int y1     = int.Parse(Request.Form["y1"]);
                int width  = int.Parse(Request.Form["width"]);
                int height = int.Parse(Request.Form["height"]);
                savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                result    = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);
            }
            break;

            case "rotate":
            {
                int    angle = DataConverter.CLng(Request.Form["angle"]);
                Bitmap bmp   = imgHelper.Rotate(vpath, angle);
                savePath += function.GetRandomString(6) + Path.GetExtension(vpath);
                result    = imgHelper.SaveImg(savePath, bmp);
                bmp.Dispose();
            }
            break;

            case "zoom":    //缩放
            {
                int width  = int.Parse(Request.Form["width"]);
                int height = int.Parse(Request.Form["height"]);
                savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                Bitmap bmp = imgHelper.ZoomImg(vpath, height, width);
                result = imgHelper.SaveImg(savePath, bmp);
            }
            break;

            case "fontwater":    //文字水印
            {
                System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg");
                savePath += "fontw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
                result   += "?" + function.GetRandomString(6);
            }
            break;

            case "imgwater":    //水印图片路径
            {
                string watervpath = Request.Form["watervpath"];
                int    trans      = DataConverter.CLng(Request.Form["trans"]);
                savePath += "imgw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans);
                result   += "?" + function.GetRandomString(6);
            }
            break;
            }
            Response.Write(result); Response.Flush(); Response.End();
        }
        if (!IsPostBack)
        {
            M_UserInfo mu       = buser.GetLogin();
            string     ipath    = Request.QueryString["ipath"].ToLower().Replace("/uploadfiles/user/", "");
            string     UserPath = "/UploadFiles/User/" + mu.UserName + mu.UserID + "/" + ipath.TrimStart('/');//不做过多的限制,如需要文件安全,则使用单独的文件服务器
            if (string.IsNullOrEmpty(UserPath) || !SafeC.IsImage(UserPath))
            {
                function.WriteErrMsg("只允许编辑图片文件!");
            }
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(Server.MapPath(savePath));
            }
            if (!File.Exists(Server.MapPath(UserPath)))
            {
                function.WriteErrMsg("需要修改的图片" + UserPath + "不存在");
            }
            NowImg_Hid.Value = SourceImg_Hid.Value = UserPath;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(UserPath));
            ImgWidth_Hid.Value  = img.Width.ToString();
            ImgHeight_Hid.Value = img.Height.ToString();
            RPT.DataSource      = GetWaterImgDT();
            RPT.DataBind();
            img.Dispose();
            //string warning;
            //----剪切图
            //vpath = ImageDealLib.imgcrop("/test/222.jpg", "/test/", 200, 200, 200, 200, ImageDealLib.FileCache.Save, out warning);
            //function.WriteErrMsg(vpath);
            //----生成水印
            //string watervpath = AddFontWater();
            //ImageDealLib.makewatermark("/test/222.jpg", "/test/usbqyr.jpg", ImageDealLib.WaterType.RightDown, "/test/", ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
            //----我们的水印
            //WaterImages water = new WaterImages();
            //string localPath = Server.MapPath("/test/222.jpg");
            //string tempurl = Server.MapPath("/test/watered12.jpg");
            //water.DrawImage(localPath, function.VToP("/Images/admin_logo.jpg"), tempurl);
        }
    }
Example #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        B_Admin.CheckIsLogged();
        if (function.isAjax())
        {
            string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径
            if (vpath.Contains("?"))
            {
                vpath = vpath.Substring(0, vpath.IndexOf("?"));
            }
            switch (action)
            {
            case "crop":    //根据提交的图片路径与宽度等参数,完成剪切
                int x1     = int.Parse(Request.Form["x1"]);
                int y1     = int.Parse(Request.Form["y1"]);
                int width  = int.Parse(Request.Form["width"]);
                int height = int.Parse(Request.Form["height"]);
                savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                result    = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);
                break;

            case "fontwater":    //文字水印
            {
                System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg");
                savePath += "fontw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
                result   += "?" + function.GetRandomString(6);
            }
            break;

            case "imgwater":    //水印图片路径
            {
                string watervpath = Request.Form["watervpath"];
                int    trans      = DataConverter.CLng(Request.Form["trans"]);
                savePath += "imgw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans);
                result   += "?" + function.GetRandomString(6);
            }
            break;
            }
            Response.Write(result); Response.Flush(); Response.End();
        }
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(IPath) || !SafeC.IsImage(IPath))
            {
                function.WriteErrMsg("只允许编辑图片文件!");
            }
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(Server.MapPath(savePath));
            }
            if (!File.Exists(Server.MapPath(IPath)))
            {
                function.WriteErrMsg("需要修改的图片" + IPath + "不存在");
            }
            NowImg_Hid.Value = SourceImg_Hid.Value = IPath;
            RPT.DataSource   = GetWaterImgDT();
            RPT.DataBind();
            //string warning;
            //----剪切图
            //vpath = ImageDealLib.imgcrop("/test/222.jpg", "/test/", 200, 200, 200, 200, ImageDealLib.FileCache.Save, out warning);
            //function.WriteErrMsg(vpath);
            //----生成水印
            //string watervpath = AddFontWater();
            //ImageDealLib.makewatermark("/test/222.jpg", "/test/usbqyr.jpg", ImageDealLib.WaterType.RightDown, "/test/", ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
            //----我们的水印
            //WaterImages water = new WaterImages();
            //string localPath = Server.MapPath("/test/222.jpg");
            //string tempurl = Server.MapPath("/test/watered12.jpg");
            //water.DrawImage(localPath, function.VToP("/Images/admin_logo.jpg"), tempurl);
        }
    }