Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
heif-rs
A Rust library to encode and decode HEIF/HEIC images using x265 and libde265, via statically-linked libheif.
⬇️ Installation
This library can be installed using Cargo. To do that, run the following command in your project's root directory:
The crate links as heif, so you import it with use heif; regardless of the package name.
[!NOTE] The first build downloads the prebuilt static binaries for your platform, so an internet connection is required (see Troubleshooting for offline builds).
🤖 Usage
Here are some examples of how to encode and decode HEIC images using this library. These snippets don't have any error handling for the sake of simplicity, but you should always check for errors in production code.
Encoding
let img = open.unwrap; // an image to be encoded
let bytes = encode.unwrap; // encode the image with default settings
write.unwrap; // save the HEIC to a file
Encoding with custom settings
use ;
use ImageEncoder;
let img = open.unwrap;
let mut bytes = Vecnew;
img.write_with_encoder.unwrap;
Decoding
let bytes = read.unwrap; // read the HEIC file
let img = decode.unwrap; // decode it into a DynamicImage
img.save.unwrap; // save it in another format
Probing (header only)
Read the image dimensions and bit depth without decoding the pixels — useful for validation or thumbnailing pipelines:
let bytes = read.unwrap;
let info = probe.unwrap;
println!;
The public API also exposes [encode_buffer] (encode a typed ImageBuffer directly), [HeifEncoder] / [HeifDecoder] for image-trait integration, [EncoderConfig] / [DecoderConfig] for full control, and [libheif_version].
Runnable examples
The examples/ directory has standalone programs covering each part of the API, runnable out of the box against the bundled assets:
💣 Troubleshooting
High bit depth (10/12-bit) encoding fails
libheif supports 8/10/12-bit HEIC for both encode and decode. Decoding high-bit-depth HEIC works out of the box (via libde265). Encoding 10/12-bit, however, depends on the bundled x265 binary, which is currently an 8-bit build — requesting 10/12-bit output makes libheif return an encoder error. If you need high-bit-depth encoding, supply your own libheif/x265 binaries built with high-bit-depth support via the HEIF_BINARIES_DIR environment variable (see below).
My build fails because it can't download the binaries
The first build fetches the prebuilt static libraries for your platform over the network. For offline or air-gapped builds, download the archive for your target from binaries-heif, extract it, and point the build at it with the HEIF_BINARIES_DIR environment variable:
$ HEIF_BINARIES_DIR=/path/to/extracted/libs cargo build
📝 License
heif-rs is released under the Apache 2.0 License. See LICENSE for details.
👨🏾💻 Author
Vinicius Egidio (vinicius.io)