Skip to content

WasmPot/image-base64-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image-base64-wasm

crates

Convert jpeg, png, gif, ico to base64, and vise versa

Compatibility

The library is compatible with wasm

To build into wasm, uncomment the target line in .cargo/config

[build]
# target = "wasm32-unknown-unknown"

Code Example

  • Read from a file
extern crate image_base64_wasm;

fn main() {
  let base64 = "base64 String";
  let image = image_base64_wasm::from_base64(base64);
  
  let image_path = "local image file path"
  let base64 = image_base64_wasm::to_base64(image_path); 
}
  • From Vec<u8> (useful for url response body)
extern crate image_base64_wasm;

fn main() {
  let base64 = "base64 String";
  let image = image_base64_wasm::from_base64(base64);
  
  let img_data: Vec<u8> = ...; // TODO replace this part
  let base64 = image_base64_wasm::vec_to_base64(img_data); 
}

Installation

Add the dependency to your Cargo.toml under [dependencies]:

image-base64-wasm = "0.5.0"

License

MIT

About

rust library to encode and decode png, jpeg or gif into base64 compatible with wasm

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%