cover

package
v0.0.0-...-15592ba Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package cover loads and resizes album art cover images.

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 Chrome OS, 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 Chrome OS 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 at 100dp. Per https://developer.android.com/training/multiscreen/screendensities, the highest screen density is xxxhdpi, which looks like it's 4x (i.e. 4 pixels per dp), for 400x400. The Pixel 4a appears to just have a device pixel ratio of 2.75, i.e. xxhdpi. It sounds like xxxhdpi resources are maybe only used for launcher icons; 3x is realistically probably the most that needs to be handled: https://stackoverflow.com/questions/21452353/android-xxx-hdpi-real-devices

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, realistically just needs something like 384x384. 512x512 is probably safer to handle future Android Auto UI changes.

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 same 512x512 images as 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

View Source
const OrigExt = ".jpg"

OrigExt is the extension for original (non-WebP) cover images.

Variables

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

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

Functions

func OrigFilename

func OrigFilename(fn string) string

OrigFilename attempts to return the original JPEG filename for the supplied WebP cover image (generated by WebPFilename). Given "foo/bar.256.webp", returns "foo/bar.jpeg". fn is returned unchanged if it doesn't appear to be a generated image.

func Scale

func Scale(ctx context.Context, bucket, baseURL, fn string,
	size, quality int, webp bool, w io.Writer) error

Scale reads the cover image at fn (corresponding to Song.CoverFilename), scales and crops it to be a square image with the supplied width and height size, and writes it in JPEG format to w.

If size is zero or negative, the original (possibly non-square) cover data is written. If webp is true, a prescaled WebP version of the image will be returned if available. The bucket and baseURL args correspond to CoverBucket and CoverBaseURL in ServerConfig. If w is an http.ResponseWriter, its Content-Type header will be set. os.ErrNotExist is replied if the specified file does not exist.

func WebPFilename

func WebPFilename(fn string, size int) string

WebPFilename returns the filename that should be used for the WebP version of JPEG file fn scaled to the specified size. fn can be a full path. Given fn "foo/bar.jpg" and size 256, returns "foo/bar.256.webp".

Types

This section is empty.

Jump to

Keyboard shortcuts

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