{"id":291,"date":"2023-05-02T11:22:28","date_gmt":"2023-05-02T08:22:28","guid":{"rendered":"https:\/\/kb.astrocroc.com\/?p=291"},"modified":"2023-05-11T14:17:34","modified_gmt":"2023-05-11T11:17:34","slug":"%d1%82%d0%b5%d1%81%d1%82","status":"publish","type":"post","link":"https:\/\/kb.astrocroc.com\/?p=291","title":{"rendered":"UserPhotoHandler"},"content":{"rendered":"\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-cs\" data-line=\"\">&lt;%@ WebHandler Language=&quot;C#&quot; Class=&quot;UserPhotoHandler&quot; Debug=&quot;true&quot; %&gt;\n\nusing System;\nusing System.Web;\nusing System.Net;\nusing System.Drawing;\nusing System.Drawing.Imaging;\nusing System.IO;\n\npublic class UserPhotoHandler : IHttpHandler \n{\n    public UserPhotoHandler() { }\n\n    Encoder myEncoder;\n    ImageCodecInfo myImageCodecInfo;\n    EncoderParameter myEncoderParameter;\n    EncoderParameters myEncoderParameters;\n    public void ProcessRequest(HttpContext context)\n    {\n\n        context.Response.ContentType = &quot;image\/jpeg&quot;;\n        \/\/string filename = context.Request.QueryString[&quot;file&quot;].Replace(&quot;https:\/\/portal.pac.ru&quot;, &quot;http:\/\/spoint&quot;);\n        string filename = context.Request.QueryString[&quot;file&quot;];\n        myImageCodecInfo = GetEncoderInfo(&quot;image\/jpeg&quot;);\n\n\n        WebClient wc = new WebClient();\n        \n        wc.Credentials = new NetworkCredential(&quot;spfarm&quot;, &quot;-----&quot;, &quot;pac&quot;);\n        \n            \n        byte[] b = wc.DownloadData(filename);\n        using(MemoryStream ms = new MemoryStream(b))\n        {\n            using (System.Drawing.Image image = System.Drawing.Image.FromStream(ms))\n            {\n                myEncoder = Encoder.Quality;\n                myEncoderParameters = new EncoderParameters(1);\n                myEncoderParameter = new EncoderParameter(myEncoder, 100L);\n                myEncoderParameters.Param[0] = myEncoderParameter;\n                Bitmap result = new Bitmap(Bitmap.FromStream(ms));\n                result.Save(context.Response.OutputStream, myImageCodecInfo, myEncoderParameters);\/\/Png);\n                \/\/result.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg, myEncoderParameter);\/\/Png);\n            }\n        }\n        context.Response.Cache.SetExpires(DateTime.Now.AddSeconds(86400));\n        context.Response.Cache.SetCacheability(HttpCacheability.Public); \n    }\n\n    private static ImageCodecInfo GetEncoderInfo(String mimeType)\n    {\n        int j;\n        ImageCodecInfo[] encoders;\n        encoders = ImageCodecInfo.GetImageEncoders();\n        for (j = 0; j &lt; encoders.Length; ++j)\n        {\n            if (encoders[j].MimeType == mimeType)\n                return encoders[j];\n        }\n        return null;\n    }\n    \n    public bool IsReusable\n    {\n        get\n        {\n            return true;\n        }\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[33],"class_list":["post-291","post","type-post","status-publish","format-standard","hentry","category-sharepoint","tag-sharepoint"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=291"}],"version-history":[{"count":2,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions"}],"predecessor-version":[{"id":293,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/291\/revisions\/293"}],"wp:attachment":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}