Skip to content

Commit df87519

Browse files
add optional feature to pixelate album art to match terminal aesthetic (#793)
1 parent a445674 commit df87519

6 files changed

Lines changed: 45 additions & 0 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,22 @@ Examples of image rendering:
247247

248248
![others](https://user-images.githubusercontent.com/40011582/172967325-d2098037-e19e-440a-a38a-5b076253ecb1.png)
249249

250+
#### Pixelate
251+
252+
If your terminal supports high-res images, but you like the pixelated look you can enable the `pixelate` feature, which also enables the `image` feature:
253+
254+
```shell
255+
cargo install spotify_player --features pixelate
256+
```
257+
258+
The amount of pixels can be tweaked via the `cover_img_pixels` config option.
259+
260+
| `cover_img_pixels` | `8` | `16` | `32` | `64` |
261+
|--------------------|-----|------|------|------|
262+
| example | <img width="100" alt="8x8" src="https://github.com/user-attachments/assets/4137aaea-ce28-4019-8cd5-2d14327e72e4" /> | <img width="100" alt="16x16" src="https://github.com/user-attachments/assets/0ca94748-093a-468c-8fb3-1f5639666eb6" /> | <img width="100" alt="32x32" src="https://github.com/user-attachments/assets/f5d0f2da-0439-47e4-91c9-3a2aa73ac90c" /> | <img width="100" alt="64x64" src="https://github.com/user-attachments/assets/d06ef731-38fa-424d-9672-313f56c193d0" /> |
263+
264+
To temporarily disable the `pixelate` feature just set `cover_img_pixels` to a high value like `512`.
265+
250266
### Notify
251267

252268
To enable desktop notification support, `spotify_player` needs to be built/installed with `notify` feature (**disabled** by default). To install the application with `notify` feature included, run:

docs/config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ All configuration files should be placed inside the application's configuration
5555
| `cover_img_width` | the width of the cover image (`image` feature only) | `5` |
5656
| `cover_img_length` | the length of the cover image (`image` feature only) | `9` |
5757
| `cover_img_scale` | the scale of the cover image (`image` feature only) | `1.0` |
58+
| `cover_img_pixels` | the amount of pixels per side of the cover image (`image` and `pixelate` feature only) | `16` |
5859
| `seek_duration_secs` | the duration (in seconds) to seek when using `SeekForward` and `SeekBackward` commands | `5` |
5960
| `sort_artist_albums_by_type` | sort albums on artist's pages by type, i.e. album or single | `false` |
6061

examples/app.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pause_icon = "▌▌"
2121
liked_icon = ""
2222
cover_img_length = 9
2323
cover_img_width = 5
24+
cover_img_pixels = 16
2425
seek_duration_secs = 5
2526

2627
[device]

spotify_player/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ streaming = ["librespot-playback", "librespot-connect"]
8888
media-control = ["souvlaki", "winit", "windows"]
8989
image = ["viuer", "dep:image"]
9090
sixel = ["image", "viuer/sixel"]
91+
pixelate = ["image"]
9192
notify = ["notify-rust"]
9293
daemon = ["daemonize", "streaming"]
9394
fzf = ["fuzzy-matcher"]

spotify_player/src/client/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,8 +1663,19 @@ impl Client {
16631663
#[cfg(feature = "image")]
16641664
if !state.data.read().caches.images.contains_key(url) {
16651665
let bytes = self.retrieve_image(url, &path, false).await?;
1666+
1667+
#[cfg(not(feature = "pixelate"))]
16661668
let image =
16671669
image::load_from_memory(&bytes).context("Failed to load image from memory")?;
1670+
#[cfg(feature = "pixelate")]
1671+
let mut image =
1672+
image::load_from_memory(&bytes).context("Failed to load image from memory")?;
1673+
1674+
#[cfg(feature = "pixelate")]
1675+
{
1676+
Self::pixelate_image(&mut image);
1677+
}
1678+
16681679
state
16691680
.data
16701681
.write()
@@ -1833,6 +1844,17 @@ impl Client {
18331844
Ok(bytes.to_vec())
18341845
}
18351846

1847+
#[cfg(feature = "pixelate")]
1848+
fn pixelate_image(image: &mut image::DynamicImage) {
1849+
let pixels = config::get_config().app_config.cover_img_pixels;
1850+
let pixelated_image = image.resize(pixels, pixels, image::imageops::FilterType::Nearest);
1851+
*image = pixelated_image.resize(
1852+
image.width(),
1853+
image.height(),
1854+
image::imageops::FilterType::Nearest,
1855+
);
1856+
}
1857+
18361858
/// Process a list of albums, which includes
18371859
/// - sort albums by the release date
18381860
/// - sort albums by the type if `sort_artist_albums_by_type` config is enabled

spotify_player/src/config/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ pub struct AppConfig {
9595
pub cover_img_width: usize,
9696
#[cfg(feature = "image")]
9797
pub cover_img_scale: f32,
98+
#[cfg(feature = "pixelate")]
99+
pub cover_img_pixels: u32,
98100

99101
#[cfg(feature = "media-control")]
100102
pub enable_media_control: bool,
@@ -307,6 +309,8 @@ impl Default for AppConfig {
307309
cover_img_width: 5,
308310
#[cfg(feature = "image")]
309311
cover_img_scale: 1.0,
312+
#[cfg(feature = "pixelate")]
313+
cover_img_pixels: 16,
310314

311315
// Because of the "creating new window and stealing focus" behaviour
312316
// when running the media control event loop on startup,

0 commit comments

Comments
 (0)