Skip to content
Client
Server

Reference / @open-music-sdk/util-artwork / artworkImage

Function: artworkImage() ​

ts
function artworkImage(
   artwork, 
   width, 
   options?
): tArtworkImage;

Defined in: artwork.ts:361

Everything an <img> needs to show an artwork width CSS pixels wide: its src, its srcset, and the width and height to lay it out by, worked out together from one reading of the artwork.

Use this where you would otherwise call artworkUrl and artworkSrcSet side by side. A browser takes src for the 1x image wherever the srcset does not offer one, and sizes an image with no width and height by the density of whichever candidate it took, so the four have to agree, and here they cannot fail to. width and height are the size the image itself is shown at: with a height and a crop that fits the artwork inside the box, that is the artwork standing in your box, not the box.

As with artworkUrl, where the URLs point is not checked unless hosts says where they may.

Parameters ​

artwork ​

tArtworkSource

The artwork as the API gave it: the URL template and, where it says, how large the image comes.

width ​

number

How wide the image is shown, in CSS pixels.

options? ​

tArtworkSrcSetOptions = {}

The densities to offer, and what artworkUrl takes.

Returns ​

tArtworkImage

src, srcset, width and height, named as an <img> names them, so the object can be assigned to one.

Throws ​

TypeError as artworkSrcSet throws it: for an artwork, a width, an option or a density that is not what it should be, and, with hosts, for a URL that is not https on one of them.

MIT licensed. Not affiliated with, endorsed by, or sponsored by Apple Inc. Apple Music and MusicKit are trademarks of Apple Inc.