コード例 #1
0
        private void CreateSheet(ThumbnailSheetCreateRequest request, Response response, IMagickImageCollection images)
        {
            int tempWidth = 0, tempHeight = 0;
            var files = Directory.GetFiles(_config.TempThumbnailPath, "thumbnail*.png").OrderBy(x => x).ToList();

            foreach (var file in files)
            {
                var image = new MagickImage(file);
                tempWidth  = image.Width;
                tempHeight = image.Height;
                images.Add(image);
            }

            var conversionNumber = tempWidth / request.ThumbnailWidth;

            tempHeight = tempHeight / conversionNumber;

            var montageSetting = new MontageSettings
            {
                Geometry        = new MagickGeometry(request.ThumbnailWidth, tempHeight),
                TileGeometry    = new MagickGeometry(GetTileGeometry(files.Count)),
                BackgroundColor = MagickColors.Black,
                BorderColor     = MagickColors.DarkGray,
                BorderWidth     = 1,
                Font            = "Arial",
                FontPointsize   = request.SheetTitleFontSize,
                FillColor       = MagickColors.LightGray,
                StrokeColor     = MagickColors.WhiteSmoke,
                Title           = request.SheetName
            };

            using (var montage = images.Montage(montageSetting))
            {
                var path = Path.Combine(_config.ThumbnailSheetPath, request.SheetName + "-sheet.jpg");
                montage.Format  = MagickFormat.Jpeg;
                montage.Quality = request.SheetQuality;
                montage.Write(path);
                response.SheetFilePath = path;
            }
        }