Exemple #1
0
        protected void GetPic_Btn_Click(object sender, EventArgs e)
        {
            //http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=3dc4538262d0f703e6e79dd83dca7d0b/7a899e510fb30f24f570e996c895d143ac4b03b8.jpg
            if (string.IsNullOrEmpty(Remote_Url.Text))
            {
                return;
            }
            string vdir    = SiteConfig.SiteOption.UploadDir;
            M_Node nodeMod = new B_Node().GetNodeXML(DataConverter.CLng(NodeID_Hid.Value));

            vdir += nodeMod.NodeDir + "/" + DateTime.Now.ToString("yyyy/MM/");
            //-------------------
            string[] imgurl = Remote_Url.Text.Split('\r');
            string   result = "";

            for (int i = 0; i < imgurl.Length; i++)
            {
                string imgname = GetFNameFromUrl(imgurl[i]);
                if (!SafeC.IsImage(imgname))
                {
                    continue;
                }
                string url = imgurl[i].ToLower().Replace(" ", "");
                if (string.IsNullOrEmpty(url) || (!url.Contains("http") && !url.Contains("https")))
                {
                    continue;
                }                                                                                                //function.WriteErrMsg("错误:" + url);
                string vpath = vdir + RemoveChar(imgname);
                try { httpHelper.DownFile(url, vpath); }
                catch (Exception) { }//function.WriteErrMsg("抓取失败,原因:" + ex.Message);
                result += vpath + "|";
            }
            result          = result.TrimEnd('|').Replace("//", "/");
            Remote_Url.Text = "";
            function.Script(this, "AddAttach('" + result + "');");
        }
        public string GetAttach(string attach)
        {
            string imgresult = "", attachresult = "";
            int    max = 3;

            foreach (string file in attach.Split('|'))
            {
                if (string.IsNullOrEmpty(file))
                {
                    continue;
                }
                if (SafeC.IsImage(file) && max > 0)//jpg,png,gif图片显示预览,只显示前三张
                {
                    imgresult += string.Format(imgTlp, Mid, file); max--;
                }
                else
                {
                    string fname = Path.GetFileName(file); fname = fname.Length > 6 ? fname.Substring(0, 6) + ".." : fname;
                    attachresult += string.Format(attachTlp, file, Path.GetExtension(file).ToLower().Replace(".", ""), fname);
                }
            }
            imgresult = string.IsNullOrEmpty(imgresult) ? "" : "<div class='thumbnail_div'>" + imgresult + "</div>";
            return(imgresult + attachresult + "<div class='clearfix'></div>");
        }
Exemple #3
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();
            }
        }
Exemple #4
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);
        }
    }
Exemple #5
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);
        }
    }
Exemple #6
0
 public static bool IsImage(string file)
 {
     return(SafeC.IsImage(file));
 }