Skip to content

Commit 6cefe44

Browse files
authored
Merge pull request #1071 from dlcs/feature/thumbs_dimensions
Output dimension on v3 manifest thumbnails
2 parents d72a3c6 + 9518400 commit 6cefe44

4 files changed

Lines changed: 35 additions & 10 deletions

File tree

src/protagonist/Orchestrator.Tests/Infrastructure/IIIF/Manifests/ManifestV3BuilderTests.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,35 @@ public async Task BuildManifest_Thumb()
139139
var manifestId = $"https://dlcs.test/iiif-manifest/{asset}";
140140
A.CallTo(() => builderUtils.GetFullQualifiedImagePath(asset, pathElement, A<Size>._, true))
141141
.Returns("https://dlcs.test/thumbs-url/");
142+
A.CallTo(() => builderUtils.GetFullQualifiedThumb(asset, pathElement, A<List<Size>>._))
143+
.Returns(new ThumbnailPathAndSize("https://dlcs.test/thumbs-url/full/!100,200/0/default.jpg",
144+
new Size(100, 200)));
142145
A.CallTo(() => builderUtils.ShouldAddThumbs(asset, A<ImageSizeDetails>._)).Returns(true);
143146

144147
var manifest = await sut.BuildManifest(manifestId, "testLabel", asset.AsList(), pathElement,
145148
ManifestType.NamedQuery, CancellationToken.None);
146-
149+
147150
manifest.Id.Should().Be(manifestId);
148-
manifest.Thumbnail.Should().NotBeNull("Has thumbnail delivery channel");
149-
151+
ValidateThumbnail(manifest.Thumbnail);
152+
150153
var canvas = manifest.Items!.Single();
151-
canvas.Thumbnail.Should().NotBeNull("Has thumbnail delivery channel");
154+
ValidateThumbnail(canvas.Thumbnail);
152155
canvas.Rendering.Should().BeNull("No file delivery channel");
153156

154157
var image = canvas.GetCanvasPaintingBody<Image>();
155158
image.Width.Should().Be(300, "Width of largest derivative");
156159
image.Height.Should().Be(200, "Height of largest derivative");
157160
image.Id.Should().Be("https://dlcs.test/thumbs-url/");
158161
image.Service.Should().BeNull("No image delivery channel");
162+
163+
void ValidateThumbnail(List<ExternalResource> thumbnails)
164+
{
165+
thumbnails.Should().NotBeNull("Has thumbnail delivery channel");
166+
var manifestThumbnail = thumbnails.Cast<Image>().Single();
167+
manifestThumbnail.Id.Should().Be("https://dlcs.test/thumbs-url/full/!100,200/0/default.jpg");
168+
manifestThumbnail.Width.Should().Be(100);
169+
manifestThumbnail.Height.Should().Be(200);
170+
}
159171
}
160172

161173
[Fact]
@@ -512,3 +524,4 @@ private static Asset GetImageAsset(string deliveryChannels) =>
512524
ImageDeliveryChannels = deliveryChannels.GenerateDeliveryChannels()
513525
};
514526
}
527+

src/protagonist/Orchestrator/Infrastructure/IIIF/Manifests/ManifestBuilderUtils.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public interface IManifestBuilderUtils
3636
List<IService> GetImageServiceForThumbnail(Asset asset, CustomerPathElement customerPathElement,
3737
List<Size> thumbnailSizes);
3838

39-
string GetFullQualifiedThumbPath(Asset asset, CustomerPathElement customerPathElement,
39+
ThumbnailPathAndSize GetFullQualifiedThumb(Asset asset, CustomerPathElement customerPathElement,
4040
List<Size> availableThumbs);
4141

4242
string GetFullQualifiedImagePath(Asset asset, CustomerPathElement customerPathElement, Size size,
@@ -87,15 +87,16 @@ public List<IService> GetImageServiceForThumbnail(Asset asset, CustomerPathEleme
8787
image2 => image2.Sizes = thumbnailSizes,
8888
image3 => image3.Sizes = thumbnailSizes);
8989

90-
public string GetFullQualifiedThumbPath(Asset asset, CustomerPathElement customerPathElement,
90+
public ThumbnailPathAndSize GetFullQualifiedThumb(Asset asset, CustomerPathElement customerPathElement,
9191
List<Size> availableThumbs)
9292
{
9393
var targetThumb = orchestratorSettings.TargetThumbnailSize;
9494

9595
// Get the thumbnail size that is closest to the system-wide TargetThumbnailSize
9696
var closestSize = availableThumbs.SizeClosestTo(targetThumb);
9797

98-
return GetFullQualifiedImagePath(asset, customerPathElement, closestSize, true);
98+
return new ThumbnailPathAndSize(GetFullQualifiedImagePath(asset, customerPathElement, closestSize, true),
99+
closestSize);
99100
}
100101

101102
public string GetFullQualifiedImagePath(Asset asset, CustomerPathElement customerPathElement, Size size,
@@ -267,3 +268,8 @@ public class ImageSizeDetails(List<Size> openThumbnails, Size maxDerivativeSize)
267268
/// </summary>
268269
public Size MaxDerivativeSize { get; } = maxDerivativeSize;
269270
}
271+
272+
/// <summary>
273+
/// Path to a thumbnail and the size of that thumbnail
274+
/// </summary>
275+
public record ThumbnailPathAndSize(string Path, Size Size);

src/protagonist/Orchestrator/Infrastructure/IIIF/Manifests/ManifestV2Builder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ private async Task<List<Canvas>> CreateCanvases(List<Asset> results, CustomerPat
104104

105105
if (BuilderUtils.ShouldAddThumbs(asset, thumbnailSizes))
106106
{
107+
var targetThumbnail =
108+
BuilderUtils.GetFullQualifiedThumb(asset, customerPathElement, thumbnailSizes.OpenThumbnails);
107109
canvas.Thumbnail = new Thumbnail
108110
{
109-
Id = BuilderUtils.GetFullQualifiedThumbPath(asset, customerPathElement, thumbnailSizes.OpenThumbnails),
111+
Id = targetThumbnail.Path,
110112
Service = BuilderUtils.GetImageServiceForThumbnail(asset, customerPathElement,
111113
thumbnailSizes.OpenThumbnails)
112114
}.AsList();

src/protagonist/Orchestrator/Infrastructure/IIIF/Manifests/ManifestV3Builder.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,15 @@ private async Task<AssetCanvas> GetCanvasForAsset(Asset asset, CustomerPathEleme
250250

251251
if (!BuilderUtils.ShouldAddThumbs(asset, thumbnailSizes)) return (annotationPage, null);
252252

253+
var targetThumbnail = BuilderUtils.GetFullQualifiedThumb(asset, customerPathElement, thumbnailSizes.OpenThumbnails);
253254
var thumbnail = new Image
254255
{
255-
Id = BuilderUtils.GetFullQualifiedThumbPath(asset, customerPathElement, thumbnailSizes.OpenThumbnails),
256+
Id = targetThumbnail.Path,
257+
Width = targetThumbnail.Size.Width,
258+
Height = targetThumbnail.Size.Height,
256259
Format = "image/jpeg",
257-
Service = BuilderUtils.GetImageServiceForThumbnail(asset, customerPathElement, thumbnailSizes.OpenThumbnails)
260+
Service = BuilderUtils.GetImageServiceForThumbnail(asset, customerPathElement,
261+
thumbnailSizes.OpenThumbnails)
258262
};
259263
return (annotationPage, thumbnail);
260264
}

0 commit comments

Comments
 (0)