diff --git a/core/artwork/artwork_internal_test.go b/core/artwork/artwork_internal_test.go index cfb7850b..c18caf73 100644 --- a/core/artwork/artwork_internal_test.go +++ b/core/artwork/artwork_internal_test.go @@ -302,6 +302,33 @@ var _ = Describe("Artwork", func() { Entry("landscape jpg image", "jpg", true, 200), ) }) + When("Requested size is larger than original", func() { + It("clamps size to original dimensions", func() { + conf.Server.CoverArtPriority = "front.png" + // front.png is 16x16, requesting 99999 should return at original size + r, _, err := aw.Get(context.Background(), alMultipleCovers.CoverArtID(), 99999, false) + Expect(err).ToNot(HaveOccurred()) + + img, _, err := image.Decode(r) + Expect(err).ToNot(HaveOccurred()) + // Should be clamped to original size (16), not 99999 + Expect(img.Bounds().Size().X).To(Equal(16)) + Expect(img.Bounds().Size().Y).To(Equal(16)) + }) + + It("clamps square size to original dimensions", func() { + conf.Server.CoverArtPriority = "front.png" + // front.png is 16x16, requesting 99999 with square should return 16x16 square + r, _, err := aw.Get(context.Background(), alMultipleCovers.CoverArtID(), 99999, true) + Expect(err).ToNot(HaveOccurred()) + + img, _, err := image.Decode(r) + Expect(err).ToNot(HaveOccurred()) + // Should be clamped to original size (16), not 99999 + Expect(img.Bounds().Size().X).To(Equal(16)) + Expect(img.Bounds().Size().Y).To(Equal(16)) + }) + }) }) }) diff --git a/core/artwork/reader_resized.go b/core/artwork/reader_resized.go index 83e6e25c..6de983ba 100644 --- a/core/artwork/reader_resized.go +++ b/core/artwork/reader_resized.go @@ -87,6 +87,11 @@ func resizeImage(reader io.Reader, size int, square bool) (io.Reader, int, error bounds := original.Bounds() originalSize := max(bounds.Max.X, bounds.Max.Y) + // Clamp size to original dimensions - upscaling wastes resources and adds no information + if size > originalSize { + size = originalSize + } + if originalSize <= size && !square { return nil, originalSize, nil }