Пример #1
0
        private void DrawPageObject(PhotobookProject project, Image <Rgba32> outputImage, PageObject obj, string photobookDirectory)
        {
            switch (obj.DefaultContentType)
            {
            // Migrated Model?
            case ContentType.Image when obj.Foreground != null && obj.Foreground?.PageObjectImageContent != null:
                DrawImage(project, outputImage, obj, photobookDirectory, obj.Foreground.PageObjectImageContent.Id.Split('|').First());
                break;

            //2021 Model
            case ContentType.Image when obj.Foreground != null && obj.Foreground.ContentType == ContentType.Image && obj.Foreground?.PageObjectImageContent != null:
                DrawImage(project, outputImage, obj, photobookDirectory, obj.Foreground.PageObjectImageContent.Id.Split('|').First());
                break;

            // Legacy Model
            case ContentType.Image when obj.Foreground != null && obj.Foreground.ContentType == ContentType.PageObjectImageContent && obj.Foreground?.Id != null:
                DrawImage(project, outputImage, obj, photobookDirectory, obj.Foreground.Id.Split('|').First());
                break;
            //2021 Model

            case ContentType.Text when obj.Foreground != null && obj.Foreground?.PageObjectTextContent?.TextId != null:
                DrawText(outputImage, obj, photobookDirectory, obj.Foreground.PageObjectTextContent.TextId);
                break;

            //Legacy Model
            case ContentType.Text when obj.Foreground != null && obj.Foreground.ContentType == ContentType.PageObjectTextContent && obj.Foreground?.TextId != null:
                DrawText(outputImage, obj, photobookDirectory, obj.Foreground.TextId);

                break;
            }
        }
Пример #2
0
 public void RenderAllPages(PhotobookProject project, string photobookDirectory, string exportDirectory)
 {
     RenderPage(project, project.Cover, photobookDirectory, exportDirectory);
     foreach (var page in project.Pages)
     {
         RenderPage(project, page, photobookDirectory, exportDirectory);
     }
 }
Пример #3
0
        public void RenderPage(PhotobookProject project, Page page, string photobookDirectory, string exportDirectory)
        {
            if (page is null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            var fileName = page.PageDescription.FirstSidePageNumber == -1 && page.PageDescription.SecondSidePageNumber == -1
            ? $"{leadingZeros}-cover"
            : page.PageDescription.FirstSidePageNumber == -1
            ? page.PageDescription.SecondSidePageNumber.ToString(leadingZeros)
            : page.PageDescription.SecondSidePageNumber == -1
            ? page.PageDescription.FirstSidePageNumber.ToString(leadingZeros)
            : $"{page.PageDescription.FirstSidePageNumber.ToString(leadingZeros)}-{page.PageDescription.SecondSidePageNumber.ToString(leadingZeros)}";

            using (Image <Rgba32> outputImage = new Image <Rgba32>(page.PageDescription.Width, page.PageDescription.Height))
            {
                foreach (var obj in page.PageBackground.PageObjects.OrderBy(o => o.Order))
                {
                    DrawPageObject(project, outputImage, obj, photobookDirectory);
                }
                foreach (var layer in page.PageLayers.OrderBy(l => l.Order))
                {
                    foreach (var obj in layer.PageObjects.OrderBy(o => o.Order))
                    {
                        DrawPageObject(project, outputImage, obj, photobookDirectory);
                    }
                }
                var           outputDirectory = Path.IsPathFullyQualified(exportDirectory) ? exportDirectory : Path.Join(photobookDirectory, exportDirectory);
                DirectoryInfo dirInfo         = new DirectoryInfo(outputDirectory);
                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                }

                var outputPath = Path.Join(outputDirectory, $"{fileName}.png");
                outputImage.Save(outputPath);
            }
        }
Пример #4
0
        private void DrawImage(PhotobookProject project, Image <Rgba32> outputImage, PageObject obj, string photobookDirectory, string fileName)
        {
            if (fileName != null)
            {
                var photoInfo = project.PhotoInformations.PhotoInformation.FirstOrDefault(p => p.FileName == fileName);
                if (photoInfo == null)
                {
                    throw new Exception($"Missing PhotoInfo for {fileName}");
                }

                var filePath = Path.Join(photobookDirectory, "Photos", fileName);

                using (Image <Rgba32> img = SixLabors.ImageSharp.Image.Load <Rgba32>(filePath))
                {
                    var rotateMode = RotateMode.None;
                    if (photoInfo.PictureOrientation != PictureOrientation.Undefined)
                    {
                        // Image Rotation (probably from exif?)
                        rotateMode = GetRotateMode(photoInfo.PictureOrientation);
                    }

                    // Apply rotation from iFolor Designer #1
                    var orthoRotOp = obj.Foreground?.PageObjectImageContent?.Processing?.ToApply?.OrthogonalRotationOperation;
                    if (orthoRotOp != null && orthoRotOp.Rotation != Rotation.Undefined)
                    {
                        rotateMode = ApplyOrthogonalRotationOperation(rotateMode, orthoRotOp.Rotation);
                    }

                    if (rotateMode != RotateMode.None)
                    {
                        img.Mutate(o => o.Rotate(rotateMode));
                    }

                    // Apple rotation from iFolor Designer #2
                    var rotOp = obj.Processing?.ToApply?.RotationOperation;
                    if (rotOp != null && rotOp.Degree != 0) //TODO abs diff
                    {
                        img.Mutate(o => o.Rotate(rotOp.Degree));
                    }

                    // Apply Visible Rect Operation
                    var visRectOp = obj.Foreground?.PageObjectImageContent?.Processing?.ToApply?.VisibleRectOperation;
                    if (visRectOp != null)
                    {
                        // Apply leveling angle
                        if (visRectOp.LevelingAngle != 0)//TODO Check ABS of Diff gt 0.01
                        {
                            //Zoom, rotate, cut
                            //TODO
                        }

                        // Apply scale factor
                        if (visRectOp.ScaleFactor != 1.0)//TODO Check ABS of Diff gt 0.01
                        {
                        }
                    }

                    img.Mutate(o => o.Resize(new SixLabors.ImageSharp.Size(Convert.ToInt32(obj.Rectangle.Width), Convert.ToInt32(obj.Rectangle.Height))));
                    outputImage.Mutate(o => o.DrawImage(img, new SixLabors.ImageSharp.Point(Convert.ToInt32(obj.Rectangle.X), Convert.ToInt32(obj.Rectangle.Y)), 1f));
                }
            }
        }