Skip to content

Commit

Permalink
Fix broken images on egui.rs (move from git lfs to normal git) (#5480)
Browse files Browse the repository at this point in the history
The images in the widget gallery on egui.rs are broken:

![image](https://github.com/user-attachments/assets/305e1041-e3e3-472d-9a52-1b90e8da053d)

~Not sure why yet, and I fail to reproduce locally.~
It's because they are on git lfs.
  • Loading branch information
emilk authored Dec 16, 2024
1 parent 3bdb19e commit f0ec2f0
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
* text=auto eol=lf
Cargo.lock linguist-generated=false
*.png filter=lfs diff=lfs merge=lfs -text
# The icon.png is needed when including eframe via git, so it may not be in lfs

# Exclude some small files from LFS:
crates/eframe/data/* !filter !diff !merge text=auto eol=lf
crates/egui_demo_lib/data/* !filter !diff !merge text=auto eol=lf
crates/egui/assets/* !filter !diff !merge text=auto eol=lf
11 changes: 9 additions & 2 deletions .github/workflows/png_only_on_lfs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ jobs:
- name: Check that png files are on git LFS
run: |
binary_extensions="png"
exclude="crates/eframe/data"
exclude_paths=(
"crates/eframe/data"
"crates/egui_demo_lib/data/"
"crates/egui/assets/"
)
# Find binary files that are not tracked by Git LFS
for ext in $binary_extensions; do
if comm -23 <(git ls-files | grep -v "^$exclude" | sort) <(git lfs ls-files -n | sort) | grep "\.${ext}$"; then
# Create grep pattern to exclude multiple paths
exclude_pattern=$(printf "|^%s" "${exclude_paths[@]}" | sed 's/^|//')
if comm -23 <(git ls-files | grep -Ev "$exclude_pattern" | sort) <(git lfs ls-files -n | sort) | grep "\.${ext}$"; then
echo "Error: Found binary file with extension .$ext not tracked by git LFS. See CONTRIBUTING.md"
exit 1
fi
Expand Down
Binary file modified crates/egui/assets/ferris.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions crates/egui_demo_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ default = ["glow", "persistence"]
# image_viewer adds about 0.9 MB of WASM
web_app = ["http", "persistence"]

http = ["ehttp", "image", "poll-promise", "egui_extras/image"]
image_viewer = ["image", "egui_extras/all_loaders", "rfd"]
http = ["ehttp", "image/jpeg", "poll-promise", "egui_extras/image"]
image_viewer = ["image/jpeg", "egui_extras/all_loaders", "rfd"]
persistence = [
"eframe/persistence",
"egui_extras/serde",
Expand All @@ -56,6 +56,10 @@ eframe = { workspace = true, default-features = false, features = [
egui = { workspace = true, features = ["callstack", "default", "log"] }
egui_demo_lib = { workspace = true, features = ["default", "chrono"] }
egui_extras = { workspace = true, features = ["default", "image"] }
image = { workspace = true, default-features = false, features = [
# Ensure we can display the test images
"png",
] }
log.workspace = true
profiling.workspace = true

Expand All @@ -70,7 +74,6 @@ wgpu = { workspace = true, features = ["webgpu", "webgl"], optional = true }

# feature "http":
ehttp = { version = "0.5", optional = true }
image = { workspace = true, optional = true, features = ["jpeg", "png"] }
poll-promise = { version = "0.3", optional = true, default-features = false }

# feature "persistence":
Expand Down
Binary file modified crates/egui_demo_lib/data/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions crates/egui_extras/src/loaders/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ impl ImageLoader for ImageCrateLoader {
}
}

if bytes.starts_with(b"version https://git-lfs") {
return Err(LoadError::FormatNotSupported {
detected_format: Some("git-lfs".to_owned()),
});
}

// (3)
log::trace!("started loading {uri:?}");
let result = crate::image::load_image_bytes(&bytes).map(Arc::new);
Expand Down

0 comments on commit f0ec2f0

Please sign in to comment.