cover

package
v0.0.0-...-fbcb358 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package cover contains cover-related constants and functions.

More than you ever wanted to know about image sizes:

Web notification icons should be 192x192 per https://developers.google.com/web/fundamentals/push-notifications/display-a-notification: "Sadly there aren't any solid guidelines for what size image to use for an icon. Android seems to want a 64dp image (which is 64px multiples by the device pixel ratio). If we assume the highest pixel ratio for a device will be 3, an icon size of 192px or more is a safe bet." On ChromeOS, icons look like they're just 58x58 on a device with a DPR of 1.6, suggesting that they're around 36x36 dp, or 72x72 on a device with a DPR of 2.

mediaSession on Chrome for Android uses 512x512 per https://web.dev/media-session/, although ChromeOS media notifications display album art at a substantially smaller size (128x128 at 1.6 DPR, for 80x80 dp or 160x160 with a DPR of 2. The code seems to specify that 72x72 (dp?) is the desired size, though: https://github.com/chromium/chromium/blob/3abe39d/components/media_message_center/media_notification_view_modern_impl.cc#L50

In the web interface, <play-view> uses 70x70 CSS pixels for the current song's cover and <fullscreen-overlay> uses 80x80 CSS pixels for the next song's cover. The song info dialog uses 192x192 CSS pixels. Favicons allegedly take a wide variety of sizes: https://stackoverflow.com/a/26807004

In the Android client, NupActivity displays cover images to (nearly) fill the screen width. The Pixel 7 and 7a both have 1080x2400 screens, so 1024x1024 seems about right there.

For Android media-session-related stuff, the framework docs are not very helpful! https://developer.android.com/reference/kotlin/android/support/v4/media/MediaMetadataCompat#METADATA_KEY_ALBUM_ART:kotlin.String: "The artwork should be relatively small and may be scaled down by the system if it is too large." Thanks, I will try to make the images relatively small and not too large.

My Android Auto head unit is only 800x480 (and probably only uses around a third of the vertical height for album art, with a blurry, scaled-up version in the background). The most expensive aftermarket AA units that I see right now have 1280x720 displays.

So I think that the Android client, which downloads and caches images in a single size, should use 1024x1024 images.

For the web interface, I don't think that there's much in the way of non-mobile devices that have a DPR above 2 (the 2021 MacBook Pro reports 2.0 for window.devicePixelRatio, for instance). 160x160 is probably enough for everything except the song info dialog (which can use the 512x512 images that were previously used for Android), but I'm going to go with 256x256 for a bit of future-proofing (and because it typically seems to be only a few KB larger than 160x160 in WebP).

Index

Constants

This section is empty.

Variables

View Source
var AllFormats = []Format{AVIF, JPEG, PNG, WebP}

AllFormats lists all formats.

View Source
var GenFormats []Format

GenFormats are supported formats for generated cover images.

View Source
var GenSizes = []int{256, 512, 1024}

GenSizes contains the sizes for which generated versions of images can be requested. See the package comment for the origin of these numbers.

View Source
var OrigFormats []Format

OrigFormats are supported formats for original (non-generated) cover images.

Functions

func DownscaleToSize

func DownscaleToSize(w, h, target int) (nw, nh int)

DownscaleToSize scales the supplied width and height so that the minimum of the two dimensions is at most target. If the minimum dimension is already less than or equal to target, or if target is less than or equal to zero, the original dimensions are returned.

func GenFilename

func GenFilename(fn string, size int, genFormat Format) string

GenFilename returns the filename that should be used for the generated version of an original file. Given fn "foo/bar.jpg", size 256, and format WebP, returns "foo/bar.256.webp".

func OrigFilenames

func OrigFilenames(fn string) []string

OrigFilenames returns possible original filenames for the supplied generated filename. Given "foo/bar.256.avif" or "foo/bar.256.webp", returns "foo/bar.png" and "foo/bar.jpg". fn is returned unchanged if it doesn't appear to be a generated image.

Types

type DrawScaler

type DrawScaler struct {
	// contains filtered or unexported fields
}

DrawScaler is a Scaler implementation using golang.org/x/image/draw.

func (*DrawScaler) Scale

func (s *DrawScaler) Scale(src image.Image, w, h int) image.Image

func (*DrawScaler) String

func (s *DrawScaler) String() string

type Format

type Format string

Format represents a supported format for cover image files.

const (
	// JPEG is a commonly-used lossy image format.
	// It's supported everywhere.
	JPEG Format = "JPEG"
	// PNG is a commonly-used lossless image format.
	// It's supported everywhere.
	PNG Format = "PNG"
	// AVIF is the AV1 Image File Format.
	// It was supported by most browsers starting in 2022 and in Android 14+ (2023).
	// See https://caniuse.com/avif and
	// https://developer.android.com/media/platform/supported-formats#image-formats.
	AVIF Format = "AVIF"
	// WebP is Google's VP8-based image format.
	// It was supported by most browsers starting in 2020 and in Android 4.0+ (2011),
	// with lossless support added in Android 10.0 (2019). See https://caniuse.com/webp and
	// https://developer.android.com/media/platform/supported-formats#image-formats.
	WebP Format = "WebP"
)

func GuessFormat

func GuessFormat(fn string) Format

GuessFormat infers the format from the supplied filename.

func (Format) ContentType

func (f Format) ContentType() string

ContentType returns f's MIME type.

func (Format) Ext

func (f Format) Ext() string

Ext returns the default extension for f.

func (Format) Generated

func (f Format) Generated() bool

Generated returns true if f is used for generated files.

func (Format) Original

func (f Format) Original() bool

Generated returns true if f is used for original files.

type Scaler

type Scaler interface {
	Scale(src image.Image, w, h int) image.Image
	String() string
}

Scaler scales images using a specific scaling algorithm.

var (
	ScaleNearestNeighbor Scaler = &DrawScaler{draw.NearestNeighbor, "draw.NearestNeighbor"}
	ScaleApproxBilinear  Scaler = &DrawScaler{draw.ApproxBiLinear, "draw.ApproxBiLinear"}
	ScaleBilinear        Scaler = &DrawScaler{draw.BiLinear, "draw.BiLinear"}
	ScaleCatmullRom      Scaler = &DrawScaler{draw.CatmullRom, "draw.CatmullRom"}
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL