Skip to content
Client
Server

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

@open-music-sdk/util-artwork ​

You probably don't want this package. Most apps install one integration and import everything from it: see Which package to install in the repository's README.

Image URLs from Apple's artwork templates. Apple sends a URL such as https://…/{w}x{h}bb.jpg, with the pixel size left for you to fill in. This package fills it in, and builds the srcset that gives a dense screen a sharper image. Strings and numbers go in, and strings and numbers come out.

Most apps install server, browser or react instead, which re-export this package's functions. Use this one to build your own client.

Installation ​

pnpm add @open-music-sdk/util-artwork

Its one dependency is core, for the check on where a URL points, and that check is all of core an app carries because of this package.

Documentation ​

Example ​

Anywhere: in a page, on a server, or wherever you write HTML. Nothing here touches the page or the network:

ts
import { artworkImage } from "@open-music-sdk/util-artwork";

const artwork = song.attributes?.artwork; // some resources have none: check before you call

if (artwork) Object.assign(img, artworkImage(artwork, 300));
// img.src     https://…/300x300bb.jpg
// img.srcset  https://…/300x300bb.jpg 1x, https://…/600x600bb.jpg 2x, https://…/900x900bb.jpg 3x
// img.width   300
// img.height  300

What's in it ​

Each function is named for what it gives back.

ExportWhat it does
artworkImage(artwork, width, options?)Everything an <img> needs, { src, srcset, width, height }, worked out together so they agree
artworkUrl(artwork, width, options?)The URL of the image width CSS pixels wide: the src alone
artworkSrcSet(artwork, width, options?)A srcset with one candidate for each pixel density: the srcset alone
FORMATSThe file formats Apple's image server converts to, which format takes
tArtworkSource, tArtworkOptions, tArtworkSrcSetOptions, tArtworkImage, tArtworkFormatWhat the functions take and give

Use artworkImage unless you need only one of the parts. Every tArtwork from @open-music-sdk/types is an artwork these functions take.

The package doesn't read devicePixelRatio, since a srcset is how a browser picks. It doesn't offer width descriptors (300w with sizes), and it doesn't load or cache an image or show a placeholder: that's the <img> element's job.

Interfaces ​

Type Aliases ​

Variables ​

Functions ​

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