bevy/crates/bevy_render
Alix Bott 31955cc78b
Add ImageFormatSetting::Guess to image loader (#13575)
# Objective

- Allow using image assets that don't have an extensions and whose
format is unknown. This is useful for loading images from arbitrary HTTP
URLs.

## Solution

- This PR adds a new variant to `ImageFormatSetting` called `Guess`. The
loader will use `image::guess_format` to deduce the format based on the
content of the file.

## Testing

- I locally removed the extension of bevy_bird_dark, and ran a modified
version of the `sprite` example:
```rust
//! Displays a single [`Sprite`], created from an image.

use bevy::{
    prelude::*,
    render::texture::{ImageFormatSetting, ImageLoaderSettings},
};

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2dBundle::default());
    commands.spawn(SpriteBundle {
        texture: asset_server
            .load_with_settings("branding/bevy_bird_dark", |s: &mut ImageLoaderSettings| {
                s.format = ImageFormatSetting::Guess
            }),
        ..default()
    });
}

```

## Changelog

### Added

`ImageFormatSetting::Guess` to automatically guess the format of an
image asset from its content.

Co-authored-by: François Mockers <mockersf@gmail.com>
2024-05-30 23:57:22 +00:00
..
macros Consolidate Render(Ui)Materials(2d) into RenderAssets (#12827) 2024-04-09 13:26:34 +00:00
src Add ImageFormatSetting::Guess to image loader (#13575) 2024-05-30 23:57:22 +00:00
Cargo.toml #12502 Remove limit on RenderLayers. (#13317) 2024-05-16 16:15:47 +00:00
README.md Add README.md to all crates (#13184) 2024-05-02 18:56:00 +00:00

Bevy Render

License Crates.io Downloads Docs Discord