Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

feat(export): offer ICO in Export As with dimension validation (#4744)

Nigel Ihza Firdausy5b1b6b075ebe
diff --git a/crates/ui-egui/src/export_dialog.rs b/crates/ui-egui/src/export_dialog.rs
index 79abeaadb..8fa630049 100644
--- a/crates/ui-egui/src/export_dialog.rs
+++ b/crates/ui-egui/src/export_dialog.rs
@@ -11,7 +11,7 @@ use crate::state::DialogKind;
use crate::theme::Tokens;
use crate::{ExportSettings, PhotocraftApp};
-const FORMATS: [(&str, &str); 5] = [("png", "PNG"), ("jpg", "JPG"), ("webp", "WebP"), ("tif", "TIFF"), ("tga", "TGA")];
+const FORMATS: [(&str, &str); 6] = [("png", "PNG"), ("jpg", "JPG"), ("webp", "WebP"), ("tif", "TIFF"), ("tga", "TGA"), ("ico", "ICO")];
/// Preferences ▸ remembered dialog settings: Export As writes the settings it was used with
/// last under its command id and seeds the next dialog from them, as Fill, Liquify and the
@@ -217,6 +217,9 @@ fn export_document(doc: &Document, f: &Map<String, Value>, max_side: Option<u32>
// Both dimensions are sent: a scale can leave a 1 px width unchanged while halving the
// height, and the engine would otherwise keep the aspect ratio from the width alone.
let (w, h) = scaled_size(doc.size.width as f64, doc.size.height as f64, scale);
+ if s_fmt(f) == "ico" && (w > 256.0 || h > 256.0) && max_side.is_none() {
+ return Err("ICO export is limited to 256 × 256 pixels; reduce the export scale".into());
+ }
if (w - doc.size.width as f64).abs() >= 1.0 || (h - doc.size.height as f64).abs() >= 1.0 {
s.execute("image.imageSize", json!({"width": w, "height": h, "resample": if max_side.is_some() { "bilinear" } else { "bicubic" }}))
.map_err(|e| e.to_string())?;
@@ -281,7 +284,8 @@ fn settings(f: &Map<String, Value>) -> ExportSettings {
/// Estimated size (bytes) from a ≤512 px proxy encode, scaled by pixel count.
fn estimate(app: &PhotocraftApp, doc: &Document, f: &Map<String, Value>) -> Option<u64> {
let export = app.services.export.as_ref()?;
- let proxy = export_document(doc, f, Some(512)).ok()?;
+ let max = if s_fmt(f) == "ico" { 256 } else { 512 };
+ let proxy = export_document(doc, f, Some(max)).ok()?;
let (bytes, _) = export(&proxy, &format!("estimate.{}", s_fmt(f)), &settings(f)).ok()?;
let scale = n(f, "scale", 100.0) / 100.0;
let full = doc.size.width as f64 * scale * doc.size.height as f64 * scale;
@@ -351,6 +355,9 @@ pub fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, f: &mut Map<String, Valu
let (bw, bh) = (n(f, "__w", f64::from(doc.size.width)), n(f, "__h", f64::from(doc.size.height)));
let (w, h) = scaled_size(bw, bh, f64::from(sc) / 100.0);
ui.label(egui::RichText::new(format!("{w} × {h} px")).color(t.text_dim).size(11.5));
+ if fmt == "ico" && (w > 256.0 || h > 256.0) {
+ ui.label(egui::RichText::new(tl!("ICO is limited to 256 × 256 pixels")).color(t.warning));
+ }
});
ui.add_space(12.0);
// Right: preview + estimated size.
@@ -492,6 +499,20 @@ fn quick_export(app: &mut PhotocraftApp, p: Value) -> Result<Value, String> {
#[cfg(test)]
mod tests {
+ #[test]
+ fn ico_export_is_available_and_rejects_oversize_output() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 300, "height": 200})).unwrap();
+ let mut f = Map::new();
+ f.insert("format".into(), json!("ico"));
+ f.insert("scale".into(), json!(100));
+ assert!(FORMATS.iter().any(|(ext, _)| *ext == "ico"));
+ assert!(export_document(&app.session.active().unwrap().doc, &f, None).err().is_some_and(|e| e.contains("256")));
+ f.insert("scale".into(), json!(50));
+ let resized = export_document(&app.session.active().unwrap().doc, &f, None).unwrap();
+ assert_eq!((resized.size.width, resized.size.height), (150, 100));
+ }
+
use super::*;
/// Export As reopens with the settings it was used with last (Preferences ▸ remembered
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 201ce4a2e..43710ab03 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -3727,3 +3727,4 @@ navigator Zoom Zvětšení
Step {step} is waiting for its dialog Krok {step} čeká na svůj dialog
@plural {n} action|{n} actions {n} akce|{n} akce|{n} akcí
Auto Add/Delete Automaticky přidat/odstranit
+ ICO is limited to 256 × 256 pixels ICO je omezen na 256 × 256 pixelů
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index d8cac0f73..b7aa6158b 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -2759,3 +2759,4 @@ curves Smooth Glätten
Step {step} is waiting for its dialog Schritt {step} wartet auf seinen Dialog
@plural {n} action|{n} actions {n} Aktion|{n} Aktionen
Auto Add/Delete Autom. hinzuf./löschen
+ ICO is limited to 256 × 256 pixels ICO ist auf 256 × 256 Pixel begrenzt
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index 337ca4584..518954664 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -3816,3 +3816,4 @@ curves Smooth Εξομάλυνση
Step {step} is waiting for its dialog Το βήμα {step} περιμένει το παράθυρο διαλόγου του
@plural {n} action|{n} actions {n} ενέργεια|{n} ενέργειες
Auto Add/Delete Αυτόματη προσθήκη/διαγραφή
+ ICO is limited to 256 × 256 pixels Το ICO περιορίζεται σε 256 × 256 εικονοστοιχεία
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 3f262bb12..a7755213b 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -2800,3 +2800,4 @@ curves Smooth Suavizar
Step {step} is waiting for its dialog El paso {step} está esperando su cuadro de diálogo
@plural {n} action|{n} actions {n} acción|{n} acciones
Auto Add/Delete Añadir/eliminar automáticamente
+ ICO is limited to 256 × 256 pixels ICO está limitado a 256 × 256 píxeles
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index 31663c240..660aa5a06 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -3120,3 +3120,4 @@ curves Smooth Lisser
Step {step} is waiting for its dialog L’étape {step} attend sa boîte de dialogue
@plural {n} action|{n} actions {n} action|{n} actions
Auto Add/Delete Ajout/suppr. auto
+ ICO is limited to 256 × 256 pixels Le format ICO est limité à 256 × 256 pixels
diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv
index 545a29aa3..05021e22c 100644
--- a/crates/ui-egui/src/i18n/hu.tsv
+++ b/crates/ui-egui/src/i18n/hu.tsv
@@ -4040,3 +4040,4 @@ cameraRaw Yellow Sárga
Loaded Camera Raw settings from {file} Camera Raw-beállítások betöltve innen: {file}
Loaded Camera Raw settings from {file} ({n} not supported) Camera Raw-beállítások betöltve innen: {file} ({n} nem támogatott)
Auto Add/Delete Automatikus hozzáadás/törlés
+ ICO is limited to 256 × 256 pixels Az ICO legfeljebb 256 × 256 képpont lehet
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index 2923b01a9..2031bbb0a 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -3107,3 +3107,4 @@ curves Smooth Haluskan
Step {step} is waiting for its dialog Langkah {step} menunggu dialognya
@plural {n} action|{n} actions {n} tindakan
Auto Add/Delete Tambah/Hapus Otomatis
+ ICO is limited to 256 × 256 pixels ICO dibatasi hingga 256 × 256 piksel
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index a4d8805e5..75c5d5317 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -4083,3 +4083,4 @@ navigator Zoom Zoom
Step {step} is waiting for its dialog Il passaggio {step} attende la sua finestra di dialogo
@plural {n} action|{n} actions {n} azione|{n} azioni
Auto Add/Delete Aggiungi/elimina automaticamente
+ ICO is limited to 256 × 256 pixels ICO è limitato a 256 × 256 pixel
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index d22fec547..67945e127 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -3796,3 +3796,4 @@ curves Smooth スムーズ
Clear Brush Controls ブラシのコントロールを消去
Reset All Locked Settings ロックされた設定をすべて初期化
Copy Texture to Other Tools テクスチャを他のツールにコピー
+ ICO is limited to 256 × 256 pixels ICO は 256 × 256 ピクセルまでです
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 56f3f5bf0..cbc506cc6 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -3289,3 +3289,4 @@ curves Smooth 매끄럽게
Step {step} is waiting for its dialog {step}단계가 대화 상자를 기다리고 있습니다
@plural {n} action|{n} actions 액션 {n}개
Auto Add/Delete 자동 추가/삭제
+ ICO is limited to 256 × 256 pixels ICO는 256 × 256픽셀로 제한됩니다
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index 3fbe7cf2c..039e1e9b4 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -3878,3 +3878,4 @@ curves Smooth Vloeiend maken
Step {step} is waiting for its dialog Stap {step} wacht op zijn dialoogvenster
@plural {n} action|{n} actions {n} handeling|{n} handelingen
Auto Add/Delete Automatisch toevoegen/verwijderen
+ ICO is limited to 256 × 256 pixels ICO is beperkt tot 256 × 256 pixels
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index 98adf9dce..27a9ff580 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -3716,3 +3716,4 @@ curves Smooth Wygładź
Step {step} is waiting for its dialog Krok {step} czeka na swoje okno dialogowe
@plural {n} action|{n} actions {n} operacja|{n} operacje|{n} operacji
Auto Add/Delete Automatyczne dodawanie/usuwanie
+ ICO is limited to 256 × 256 pixels ICO jest ograniczony do 256 × 256 pikseli
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index f2f1034a1..935ffc327 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -3908,3 +3908,4 @@ layerLabel No Color Sem cor
Step {step} is waiting for its dialog A etapa {step} está aguardando sua caixa de diálogo
@plural {n} action|{n} actions {n} ação|{n} ações
Auto Add/Delete Adicionar/excluir automaticamente
+ ICO is limited to 256 × 256 pixels ICO é limitado a 256 × 256 pixels
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 9a6575262..43f69ff4d 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -3064,3 +3064,4 @@ curves Smooth Сгладить
Step {step} is waiting for its dialog Шаг {step} ожидает своего диалога
@plural {n} action|{n} actions {n} операция|{n} операции|{n} операций
Auto Add/Delete Автодобавление/удаление
+ ICO is limited to 256 × 256 pixels ICO ограничен размером 256 × 256 пикселей
diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsv
index 2c56ff9ab..94630620f 100644
--- a/crates/ui-egui/src/i18n/sr.tsv
+++ b/crates/ui-egui/src/i18n/sr.tsv
@@ -4194,3 +4194,4 @@ shape Appearance Izgled
# Custom print paper (#3820)
Paper Width Širina papira
Paper Height Visina papira
+ ICO is limited to 256 × 256 pixels ICO je ograničen na 256 × 256 piksela
diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv
index 1eb8e16f4..1ac075c29 100644
--- a/crates/ui-egui/src/i18n/tr.tsv
+++ b/crates/ui-egui/src/i18n/tr.tsv
@@ -3851,3 +3851,4 @@ cameraData Lens Lens
Loaded Camera Raw settings from {file} Camera Raw ayarları {file} dosyasından yüklendi
Loaded Camera Raw settings from {file} ({n} not supported) Camera Raw ayarları {file} dosyasından yüklendi ({n} desteklenmiyor)
Auto Add/Delete Otomatik Ekle/Sil
+ ICO is limited to 256 × 256 pixels ICO 256 × 256 piksel ile sınırlıdır
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index 921b7b1e0..d6f049276 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -3817,3 +3817,4 @@ curves Smooth Згладити
Step {step} is waiting for its dialog Крок {step} очікує на свій діалог
@plural {n} action|{n} actions {n} операція|{n} операції|{n} операцій
Auto Add/Delete Автододавання/видалення
+ ICO is limited to 256 × 256 pixels ICO обмежено розміром 256 × 256 пікселів
diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv
index 68acfe2db..b48531e18 100644
--- a/crates/ui-egui/src/i18n/vi.tsv
+++ b/crates/ui-egui/src/i18n/vi.tsv
@@ -3604,3 +3604,4 @@ curves Smooth Làm mượt
Import .GRD Nhập .GRD
Choose a gradient file (.grd). Chọn tệp chuyển sắc (.grd).
Auto Add/Delete Tự động thêm/xóa
+ ICO is limited to 256 × 256 pixels ICO giới hạn ở 256 × 256 pixel
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index d8fc71598..9ca765cd9 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -2724,3 +2724,4 @@ curves Smooth 平滑
Step {step} is waiting for its dialog 步骤 {step} 正在等待其对话框
@plural {n} action|{n} actions {n} 个动作
Auto Add/Delete 自动添加/删除
+ ICO is limited to 256 × 256 pixels ICO 最大为 256 × 256 像素
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index 1219fa31d..84b93d1cf 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -2709,3 +2709,4 @@ curves Smooth 平滑
Step {step} is waiting for its dialog 步驟 {step} 正在等待其對話框
@plural {n} action|{n} actions {n} 個動作
Auto Add/Delete 自動增加/刪除
+ ICO is limited to 256 × 256 pixels ICO 最大為 256 × 256 像素