digirati-co-uk / iiif-net

IIIF models for dotnet
MIT License
3 stars 1 forks source link

Support for ImageService3 #10

Closed ra-magnus-welander closed 2 years ago

ra-magnus-welander commented 2 years ago

Also added new ImageService2Reference that inherits from ResourceBase so we can use the Profile property.

I wasn't sure what to do with V2ServiceReference which has a serializer associated with it, but i guess that the two should be merged into one class.

donaldgray commented 2 years ago

Hi @ra-magnus-welander - do you have examples of how you are using the 3 new classes?

ra-magnus-welander commented 2 years ago

Sorry for taking so long in coming back to you! Here is an example for the Reference-classes:

            canvas.Items = new List<AnnotationPage>
            {
                new AnnotationPage
                {
                    Id = $"{serverUrl}{image.IIIFIdentifier}/annotationpage",
                    Items = new List<IAnnotation>
                    {
                        new PaintingAnnotation
                        {
                            Id = $"{serverUrl}{image.IIIFIdentifier}/annotation",
                            Body = new Image
                            {
                                Id = $"{serverUrl}{image.IIIFIdentifier}/full/max/0/default.jpg",
                                Height = image.Height,
                                Width = image.Width,
                                Format = "image/jpeg",
                                Service = new List<IService>
                                {
                                    new ImageService3Reference
                                    {
                                        Id = $"{serverUrl}v3/{image.IIIFIdentifier}",
                                        Profile = "level1"
                                    },
                                    new ImageService2Reference
                                    {
                                        Id = $"{serverUrl}v2/{image.IIIFIdentifier}",
                                        Profile = ImageService2.Level1Profile
                                    }
                                }
                            },
                            Target = canvas
                        }
                    }
                }        
            };
ra-magnus-welander commented 2 years ago

And here is an example of ImageService3:

            var imageInfo = new ImageService3
            {
                Id = $"{serverUrl}v3/{image.IIIFIdentifier}",
                Width = image.Width,
                Height = image.Height,
                Profile = complianceLevel
            };

            if (assetModel.DataSource == "arkis")
            {
                imageInfo.Rights = arkisDataService.GetRättighetsmärkning(assetModel.Id);
            }

            imageInfo.ExtraFeatures = new List<string>
            {
                "mirroring",
                "profileLinkHeader",
                "rotationArbitrary",
                "rotationBy90s",
                "sizeByPct"
            };
donaldgray commented 2 years ago

@ra-magnus-welander - thanks for the feedback.

ImageService3 looks great - thanks for that.

The ImageService2Reference and ImageService3Reference classes are redundant, you can use ImageService2 and ImageService3 in their place, with only the relevant properties set. For example, your first example becomes:

canvas.Items = new List<AnnotationPage>
{
    new AnnotationPage
    {
        Id = $"{serverUrl}{image.IIIFIdentifier}/annotationpage",
        Items = new List<IAnnotation>
        {
            new PaintingAnnotation
            {
                Id = $"{serverUrl}{image.IIIFIdentifier}/annotation",
                Body = new Image
                {
                    Id = $"{serverUrl}{image.IIIFIdentifier}/full/max/0/default.jpg",
                    Height = image.Height,
                    Width = image.Width,
                    Format = "image/jpeg",
                    Service = new List<IService>
                    {
                        new ImageService3  // ImageService3Reference
                        {
                            Id = $"{serverUrl}v3/{image.IIIFIdentifier}",
                            Profile = "level1"
                        },
                        new ImageService2  // ImageService2Reference
                        {
                            Id = $"{serverUrl}v2/{image.IIIFIdentifier}",
                            Profile = ImageService2.Level1Profile
                        }
                    }
                },
                Target = canvas
            }
        }
    }        
};

The .AsJson() extension method is configured to ignore null + default values so only the Id and Profile properties will be output.

I'll merge this PR as-is now and make a follow up PR to remove the 2 reference classes. I'll create a new release of the nuget package once that is done.

Thanks for the input! 👍