Esempio n. 1
0
        public static Stream GetResizedImage(ImageMediaSource src, int?maxWidth, int?maxHeight)
        {
            // load file
            if (!src.Exists)
            {
                Log.Info("Requested resized image for non-existing source {0}", src.GetDebugName());
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return(Stream.Null);
            }

            // create cache path
            string filename = String.Format("resize_{0}_{1}_{2}.jpg", src.GetUniqueIdentifier(), maxWidth, maxHeight);

            // check for existence on disk
            if (!cache.Contains(filename))
            {
                Image orig;
                using (var impersonator = src.GetImpersonator())
                {
                    orig = Image.FromStream(src.Retrieve());
                }

                if (!ResizeImage(orig, cache.GetPath(filename), maxWidth, maxHeight))
                {
                    WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError);
                    return(Stream.Null);
                }
            }

            return(StreamImage(new ImageMediaSource(cache.GetPath(filename))));
        }
Esempio n. 2
0
        public static Stream GetResizedImage(ImageMediaSource src, int?maxWidth, int?maxHeight)
        {
            // load file
            if (!src.Exists)
            {
                Log.Info("Requested resized image for non-existing source {0}", src.GetDebugName());
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return(Stream.Null);
            }

            // create cache path
            string tmpDir = Path.Combine(Path.GetTempPath(), "MPExtended", "imagecache");

            if (!Directory.Exists(tmpDir))
            {
                Directory.CreateDirectory(tmpDir);
            }
            string cachedPath = Path.Combine(tmpDir, String.Format("rs_{0}_{1}_{2}.jpg", src.GetUniqueIdentifier(), maxWidth, maxHeight));

            // check for existence on disk
            if (!File.Exists(cachedPath))
            {
                Image orig;
                using (var impersonator = src.GetImpersonator())
                {
                    orig = Image.FromStream(src.Retrieve());
                }

                if (!ResizeImage(orig, cachedPath, maxWidth, maxHeight))
                {
                    WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError);
                    return(Stream.Null);
                }
            }

            return(StreamImage(new ImageMediaSource(cachedPath)));
        }
Esempio n. 3
0
        public static Stream GetResizedImage(ImageMediaSource src, int? maxWidth, int? maxHeight)
        {
            // load file
            if (!src.Exists)
            {
                Log.Info("Requested resized image for non-existing source {0}", src.GetDebugName());
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return Stream.Null;
            }

            // create cache path
            string tmpDir = Path.Combine(Path.GetTempPath(), "MPExtended", "imagecache");
            if (!Directory.Exists(tmpDir))
                Directory.CreateDirectory(tmpDir);
            string cachedPath = Path.Combine(tmpDir, String.Format("rs_{0}_{1}_{2}.jpg", src.GetUniqueIdentifier(), maxWidth, maxHeight));

            // check for existence on disk
            if (!File.Exists(cachedPath))
            {
                Image orig;
                using (var impersonator = src.GetImpersonator())
                {
                    orig = Image.FromStream(src.Retrieve());
                }

                if (!ResizeImage(orig, cachedPath, maxWidth, maxHeight))
                {
                    WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError);
                    return Stream.Null;
                }
            }

            return StreamImage(new ImageMediaSource(cachedPath));
        }
Esempio n. 4
0
        public static Stream GetResizedImage(ImageMediaSource src, int? maxWidth, int? maxHeight)
        {
            // load file
            if (!src.Exists)
            {
                Log.Info("Requested resized image for non-existing source {0}", src.GetDebugName());
                WCFUtil.SetResponseCode(System.Net.HttpStatusCode.NotFound);
                return Stream.Null;
            }

            // create cache path
            string filename = String.Format("resize_{0}_{1}_{2}.jpg", src.GetUniqueIdentifier(), maxWidth, maxHeight);

            // check for existence on disk
            if (!cache.Contains(filename))
            {
                Image orig;
                using (var impersonator = src.GetImpersonator())
                {
                    orig = Image.FromStream(src.Retrieve());
                }

                if (!ResizeImage(orig, cache.GetPath(filename), ImageFormat.Jpeg, maxWidth, maxHeight))
                {
                    WCFUtil.SetResponseCode(System.Net.HttpStatusCode.InternalServerError);
                    return Stream.Null;
                }
            }

            return StreamImage(new ImageMediaSource(cache.GetPath(filename)));
        }