Exemple #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            services.AddFilehook(FileSystemConsts.FileSystemStorageName)
            .AddImageSharpImageProccessor()
            .AddFallbackFileProccessor()
            .AddFileSystemStorage(options =>
            {
                options.BasePath = "./wwwroot";
                options.CdnUrl   = "http://localhost:5000";
            })
            .AddMetadata(builder => {
                builder.Entity <Article>(entity => {
                    entity.HasId(x => x.Id.ToString());
                    entity.HasName("MyArticle");

                    var decodeOptions = new ImageEncodeOptions {
                        MimeType = "image/jpeg"
                    };

                    entity.Property(x => x.CoverImageFileName)
                    .HasPostfix("FileName")
                    .HasImageStyle(new ImageStyle("thumb", new ImageResizeOptions {
                        Width = 310
                    }, decodeOptions))
                    .HasImageStyle(new ImageStyle("retina_thumb", new ImageResizeOptions {
                        Height = 220
                    }, decodeOptions))
                    .HasImageStyle(new ImageStyle("iphone", new ImageResizeOptions {
                        Width = 640, Height = 1136
                    }, decodeOptions))
                    .HasImageStyle(new ImageStyle("ipad", new ImageResizeOptions {
                        Width = 768, Height = 1024
                    }, decodeOptions))
                    .HasImageStyle(new ImageStyle("ipad_retina", new ImageResizeOptions {
                        Width = 1536, Height = 2048
                    }, decodeOptions))
                    .HasImageStyle(new ImageStyle("desktop_hd", new ImageResizeOptions {
                        Height = 720
                    }, decodeOptions))
                    .HasImageStyle(new ImageStyle("desktop_full_hd", new ImageResizeOptions {
                        Height = 1080, Mode = ImageResizeMode.ShrinkLarger
                    }, decodeOptions))
                    .HasImageStyle(new ImageStyle("desktop_retina", new ImageResizeOptions {
                        Height = 1080, Mode = ImageResizeMode.ShrinkLarger
                    }, decodeOptions));

                    entity.Property(x => x.AttachmentFileName)
                    .HasName("Attachment");
                });
            });
        }
        /// <summary>
        /// Resize style
        /// </summary>
        /// <param name="name"> Style name </param>
        /// <param name="resizeWidth"> Max width (0 for auto) </param>
        /// <param name="resizeHeight"> Max height (0 for auto) </param>
        /// <param name="resizeMode"> Resize mode </param>
        public HasImageStyleAttribute(
            string name,
            int resizeWidth,
            int resizeHeight,
            ImageResizeMode resizeMode = ImageResizeMode.PreserveAspectRatio,
            Resampler resampler        = Resampler.Auto,
            int quality = 100) : base(name)
        {
            var resizeOptions = new ImageResizeOptions
            {
                Width  = resizeWidth,
                Height = resizeHeight,
                Mode   = resizeMode
            };

            var decodeOptions = new ImageEncodeOptions
            {
                Quality = quality
            };

            Style = new ImageStyle(name, resizeOptions, decodeOptions);
        }