Kindeditor 远程图片宽度自动适应

很多客户对kindeditor编辑器中的图片操作不熟,上传图片完成后,不注意图片宽度问题,往往造成图片宽度超出内容区域,使得一部分图片被隐藏,不友好。

为解决这个问题,让上传的图片自动适应内容区域的宽度,修改了下upload_json.ashx代码,很简单如下:

//大概是91行的位置,图片保存完成,操作
imgFile.SaveAs(filePath);
        
        String fileUrl = saveUrl + newFileName;

        Hashtable hash = new Hashtable();
        hash["error"] = 0;
        hash["url"] = fileUrl;

        #region 计算图片宽度
        System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(filePath);
        int _width = bmp.Width;
        bmp.Dispose();
        if (_width > 930)//你内容区域的宽度
        {
            hash["width"] = "100%";
        }
        #endregion

        context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8");
        context.Response.Write(JsonMapper.ToJson(hash));
        context.Response.End();

 

posted @ 2013-04-03 11:41  jackchain  阅读(672)  评论(0编辑  收藏  举报