示例#1
0
        public void GenerateCoverImageOfRequestedMaxSize_GivenVariousThmbnailSizes_ThumbnailIsCorrectSize(int requestedSize, int originalWidth, int originalHeight, int expectedWidth, int expectedHeight)
        {
            // Setup
            var book = SetupBook("coverImage.png", originalWidth, originalHeight);

            // System under test
            BookThumbNailer.GenerateCoverImageOfRequestedMaxSize(book, requestedSize);

            // Verification
            string expectedThumbnailFilename = book.FolderPath.CombineForPath($"thumbnail-{requestedSize}.png");

            Assert.That(RobustFile.Exists(expectedThumbnailFilename), Is.True, "Thumbnail does not exist at expected path");

            using (var image = System.Drawing.Image.FromFile(expectedThumbnailFilename))
            {
                Assert.That(image.Width, Is.EqualTo(expectedWidth), "image width");
                Assert.That(image.Height, Is.EqualTo(expectedHeight), "image height");
            }
        }
示例#2
0
        public static void CreateThumbnailArtifact(CreateArtifactsParameters parameters)
        {
            if (String.IsNullOrWhiteSpace(parameters.ThumbnailOutputInfoPath))
            {
                return;
            }

            var outputPaths = new List <string>();

            int[] requestedHeights = new int[2] {
                256, 70
            };
            foreach (int height in requestedHeights)
            {
                // A potential "enhancement" is that we could try to re-use the thumbnail generated when making an ePUB.
                //   That could be helpful if creating new thumbnails was a big enough cost
                // The ePub Path looks like this: $"%TEMP%\\ePUB_export\\{i}\\{book.Title}\\thumbnail-{height}.png"
                // (where i is an integer between 0-19. Depends on whether it's been locked or not.)
                //
                // For now, we'll just create the thumbnail every time
                // It makes the code simpler than having fallback logic not to mention the complications of determining which folder the ePub is in, whether it's really up-to-date, etc.
                string thumbnailPath = BookThumbNailer.GenerateCoverImageOfRequestedMaxSize(_book, height);

                AppendPathIfExists(thumbnailPath, outputPaths);
            }

            string shareThumbnail = BookThumbNailer.GenerateSocialMediaSharingThumbnail(_book);

            AppendPathIfExists(shareThumbnail, outputPaths);

            using (var writer = new StreamWriter(parameters.ThumbnailOutputInfoPath, append: false))
            {
                foreach (var path in outputPaths)
                {
                    writer.WriteLine(path);
                }
            }
        }