zng

Module image

source
Expand description

Images service, widget and other types.

§Image

The Image! widget is the primary way of presenting images, the example below defines a repeating pattern image as the window background, the image source is embedded in this case, see ImageSource for other supported sources.

use zng::prelude::*;

Window! {
    widget::background = Image! {
        source = include_bytes!("../res/image/pattern.png");
        img_fit = zng::image::ImageFit::None;
        img_repeat = true;
    }
}

§Mask

Mask images are loaded just like normal images, the mask::mask_image property can be set on any widget to apply a mask to it. The example below applies a mask to a button, by default the mask uses the alpha channel, see mask for more details.

use zng::{prelude::*, image::mask};

Button! {
    mask::mask_image = include_bytes!("../res/image/star.png");
}

§Service

The IMAGES service manages image loading, the image cache and image rendering. Image decoding is implemented by the view-process, for this reason to get image with actual pixels the service must be used in a headed app or headless app with renderer, in a headless app without renderer all images are a placeholder dummy.

The images service also define security limits, the IMAGES.limits variable to configure these limits. See ImageLimits::default for the defaults.

use zng::{prelude::*, image};

image::IMAGES.limits().modify(|l| {
    let l = l.to_mut();
    l.allow_uri = image::UriFilter::allow_host("httpbin.org");
    l.max_encoded_len = 1.megabytes();
    l.max_decoded_len = 10.megabytes();
});

The example above changes the global limits to allow image downloads only from an specific host and only allow images with sizes less or equal to 1 megabyte and that only expands to up to 10 megabytes after decoding.

§Full API

See zng_ext_image for the full image API and zng_wgt_image for the full widget API.

Modules§

  • Mask image properties.

Structs§

Enums§

Functions§

Type Aliases§