Exemplo n.º 1
0
        private void GenerateSlideThumbnails(ICollection <Slide> slides)
        {
            Directory.CreateDirectory(AppDirectories.SlideThumbs);
            var existingThumbs = from file in Directory.EnumerateFiles(AppDirectories.SlideThumbs, "*.jpeg")
                                 select file;
            var existingThumbsCount = existingThumbs.Count();

            if (slides.Count == existingThumbsCount)
            {
                return;
            }

            foreach (var slide in slides)
            {
                var existingSlideThumb = from file in existingThumbs
                                         where file.ToLower().Contains($"{slide.Name.ToUrlSlug()}")
                                         select file;
                if (existingSlideThumb.Any())
                {
                    continue;
                }

                logger.LogInformation("Generating thumbnail of slide {id}: {name}..", slide.Id, slide.Name);
                using (var osr = new OpenSlide(slide.FilePath))
                {
                    var thumb = osr.GetThumbnail(new Size(400, 400));
                    thumb.Save($@"{AppDirectories.SlideThumbs}{slide.Name.ToUrlSlug()}.jpeg", ImageFormat.Jpeg);
                }
            }
        }
Exemplo n.º 2
0
 public void TestThumbnail()
 {
     Assert.AreEqual(new Size(100, 83), osr.GetThumbnail(new SizeL(100, 100)).Size);
 }