コード例 #1
0
ファイル: Root.cs プロジェクト: lemontrue/Elfinder
        internal ImageWithMime GenerateThumbnail(FullPath originalImage)
        {
            string name = originalImage.File.Name;

            for (int i = name.Length - 1; i >= 0; i--)
            {
                if (name[i] == '_')
                {
                    name = name.Substring(0, i);
                    break;
                }
            }
            string fullPath = originalImage.File.DirectoryName + "\\" + name + originalImage.File.Extension;

            if (_thumbnailsDirectory != null)
            {
                FileInfo thumbPath;
                if (originalImage.File.FullName.StartsWith(_thumbnailsDirectory.FullName))
                {
                    thumbPath = originalImage.File;
                }
                else
                {
                    thumbPath = new FileInfo(Path.Combine(_thumbnailsDirectory.FullName, originalImage.RelativePath));
                }
                if (!thumbPath.Exists)
                {
                    if (!thumbPath.Directory.Exists)
                    {
                        System.IO.Directory.CreateDirectory(thumbPath.Directory.FullName);
                    }
                    using (FileStream thumbFile = thumbPath.Create())
                    {
                        using (FileStream original = File.OpenRead(fullPath))
                        {
                            ImageWithMime thumb = PicturesEditor.GenerateThumbnail(original, _thumbnailsSize, true);
                            thumb.ImageStream.CopyTo(thumbFile);
                            thumb.ImageStream.Position = 0;
                            return(thumb);
                        }
                    }
                }
                else
                {
                    return(new ImageWithMime(PicturesEditor.ConvertThumbnailExtension(thumbPath.Extension), thumbPath.OpenRead()));
                }
            }
            else
            {
                using (FileStream original = File.OpenRead(fullPath))
                {
                    return(PicturesEditor.GenerateThumbnail(original, _thumbnailsSize, true));
                }
            }
        }
コード例 #2
0
ファイル: Connector.cs プロジェクト: lemontrue/Elfinder
        public ActionResult GetThumbnail(HttpRequestBase request, HttpResponseBase response, string hash)
        {
            string thumbHash = hash;

            if (thumbHash != null)
            {
                FullPath path = _driver.ParsePath(thumbHash);
                if (!path.IsDirectoty && path.Root.CanCreateThumbnail(path.File))
                {
                    if (!HttpCacheHelper.IsFileFromCache(path.File, request, response))
                    {
                        ImageWithMime thumb = path.Root.GenerateThumbnail(path);
                        return(new FileStreamResult(thumb.ImageStream, thumb.Mime));
                    }
                    response.ContentType = Helper.GetMimeType(path.Root.PicturesEditor.ConvertThumbnailExtension(path.File.Extension));
                    response.End();
                }
            }
            return(new EmptyResult());
        }