This class is a place to gather the methods that have to do with making thumbnails of pages of books. Three of the methods were previously methods of Book itself, but the fourth (MakeThumbnailOfCover) needed to do too much UI stuff to belong in a model class, so it seemed worth pulling all this out to a new class. In live code there is typically only one instance of this created by the ApplicationServer. In test code they may be created as needed; nothing requires this to be a singleton. Indeed, it could be a static class except that it requires the HtmlThumbNailer.
        /// <summary>
        /// Generates the cover image for a book, e.g. the thumbnail used on Bloom Library
        /// </summary>
        /// <param name="book"></param>
        /// <param name="requestedSize">The maximum size of either dimension</param>
        public static string GenerateCoverImageOfRequestedMaxSize(Book.Book book, int requestedSize)
        {
            HtmlThumbNailer.ThumbnailOptions thumbnailOptions = BookThumbNailer.GetCoverThumbnailOptions(requestedSize, new Guid());
            BookThumbNailer.CreateThumbnailOfCoverImage(book, thumbnailOptions, null);

            string thumbnailDestination = Path.Combine(book.FolderPath, thumbnailOptions.FileName);

            return(thumbnailDestination);
        }
        /// <summary>
        /// Generates a thumbnail suitable for sharing on Facebook
        /// </summary>
        /// <param name="book"></param>
        /// <returns></returns>
        public static string GenerateSocialMediaSharingThumbnail(Book.Book book)
        {
            // 300 x 300 is picked so that FB will consistently generate a thumbnail that is:
            // * to the left of the link
            // * a fixed aspect ratio (happens to be square)
            // * has enough pixels to work with high res screens with devicePixelRatio up to 4. (FB Mobile App was showing it as 75 CSS pixels)
            // See BL-8406
            int size    = 300;
            var options = new HtmlThumbNailer.ThumbnailOptions
            {
                CenterImageUsingTransparentPadding = true,
                RequestId = new Guid(),
                Height    = size,
                Width     = size,
            };

            options.FileName = $"thumbnail-{options.Width}x{options.Height}.png";

            BookThumbNailer.CreateThumbnailOfCoverImage(book, options, null);

            string thumbnailDestination = Path.Combine(book.FolderPath, options.FileName);

            return(thumbnailDestination);
        }
Esempio n. 3
0
 public EpubMakerAdjusted(Bloom.Book.Book book, BookThumbNailer thumbNailer)
     : base(thumbNailer, new NavigationIsolator())
 {
     this.Book = book;
 }