From 794ddc9b8f9e373e8eaff064bf008ea396c30289 Mon Sep 17 00:00:00 2001 From: Rasmus Date: Sat, 12 Sep 2026 18:57:22 +0200 Subject: [PATCH] fix(art): preserve uncropped card art aspect ratio using fit=inside --- README.md | 2 +- main/scryfall_client.c | 4 ++-- main/ui_task.c | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1b89845..012daf2 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ All local card details and artwork are stored in LittleFS mounted at `/spiffs`: ├── mappings.json # Scanned UID -> Card Name mapping table └── cards/ ├── .json # Cached Scryfall card data (Mana, Oracle, Type, P/T) - └── .jpg # Cached 200x110 Baseline JPEG art crop + └── .jpg # Cached Baseline JPEG art crop (aspect-ratio preserved) ``` --- diff --git a/main/scryfall_client.c b/main/scryfall_client.c index 447802e..d72d1cd 100644 --- a/main/scryfall_client.c +++ b/main/scryfall_client.c @@ -421,8 +421,8 @@ static esp_err_t scryfall_do_fetch(const char *card_name, const char *uid) char enc_img[512]; url_encode(image_url, enc_img, sizeof(enc_img)); char proxy_url[600]; - /* wsrv.nl converts Scryfall's progressive JPEG to a lightweight 200x110 baseline JPEG */ - snprintf(proxy_url, sizeof(proxy_url), "https://wsrv.nl/?url=%s&w=200&h=110&fit=cover&output=jpg", enc_img); + /* wsrv.nl converts Scryfall's progressive JPEG to a lightweight baseline JPEG preserving original aspect ratio */ + snprintf(proxy_url, sizeof(proxy_url), "https://wsrv.nl/?url=%s&w=200&h=150&fit=inside&output=jpg", enc_img); esp_err_t dl = http_download_file(proxy_url, jpg_path); if (dl != ESP_OK) { ESP_LOGW(TAG, "proxied image download failed, trying direct: %s", image_url); diff --git a/main/ui_task.c b/main/ui_task.c index b3314d6..c8fd5c5 100644 --- a/main/ui_task.c +++ b/main/ui_task.c @@ -199,6 +199,23 @@ static bool load_art_crop(const char *uid) return false; } + /* Automatically purge legacy 200x110 cropped art and re-fetch with full uncropped aspect ratio */ + if (out_info.width == 200 && out_info.height == 110 && wifi_manager_connected()) { + ESP_LOGI(TAG, "Purging legacy 200x110 cropped art: %s", jpg_path); + free(jpg_buf); + remove(jpg_path); + if (s_card_name[0] != '\0') { + scryfall_fetch_request(s_card_name, uid); + } else { + char *looked_up_name = NULL; + if (storage_manager_lookup_name(uid, &looked_up_name) == ESP_OK && looked_up_name != NULL) { + scryfall_fetch_request(looked_up_name, uid); + free(looked_up_name); + } + } + return false; + } + if (out_info.width > 240) { cfg.out_scale = (out_info.width > 480) ? JPEG_IMAGE_SCALE_1_4 : JPEG_IMAGE_SCALE_1_2; esp_jpeg_get_image_info(&cfg, &out_info);