1 个不稳定版本
0.1.0 | 2021年9月4日 |
---|
#900 in 图像
14KB
113 代码行
ase-swatch
Rust和WebAssembly库,用于编码和创建用于颜色和调色的Adobe Swatch Exchange (ASE) 文件。
该项目基于由Marcos A Ojeda编写的Python库swatch。
使用方法
在Rust中
use ase_swatch::create_ase;
use ase_swatch::types::*;
let swatches = vec![
ObjectSwatch {
name: "Palette 1".to_string(),
swatches: vec![
ObjectColor {
name: "Red".to_string(),
object_type: ObjectColorType::Global,
data: Color {
mode: ColorMode::Rgb,
values: vec![1.0, 0.0, 0.0],
},
},
ObjectColor {
name: "Green".to_string(),
object_type: ObjectColorType::Global,
data: Color {
mode: ColorMode::Rgb,
values: vec![0.0, 1.0, 0.0],
},
},
ObjectColor {
name: "Blue".to_string(),
object_type: ObjectColorType::Global,
data: Color {
mode: ColorMode::Rgb,
values: vec![0.0, 0.0, 1.0],
},
},
],
}
];
let colors = vec![
ObjectColor {
name: "Blue".to_string(),
object_type: ObjectColorType::Global,
data: Color {
mode: ColorMode::Rgb,
values: vec![0.0, 0.0, 1.0],
},
},
];
let result: Vec<u8> = create_ase(&swatches, &colors);
// resulting vector of bytes can be written as a binary file
在JavaScript中
前置步骤
- 克隆仓库
- 使用适当的构建目标,通过
wasm-pack
构建WebAssembly二进制文件。
该库公开了一个create_ase_js()
函数,可以从JavaScript中以类似create_ase
函数的签名调用。
const swatches = [
{
name: "Palette 1",
swatches: [
{
name: "Red",
object_type: "Global",
data: {
mode: "Rgb",
values: [1.0, 0.0, 0.0],
},
},
{
name: "Green",
object_type: "Global",
data: {
mode: "Rgb",
values: [0.0, 1.0, 0.0],
},
},
{
name: "Blue",
object_type: "Global",
data: {
mode: "Rgb",
values: [0.0, 0.0, 1.0],
},
},
],
},
];
let colors = [
{
name: "Blue",
object_type: "Global",
data: {
mode: "Rgb",
values: [0.0, 0.0, 1.0],
},
},
];
const result = create_ase_js(swatches, colors);
// resulting array is a `Uint8Array` of the created ASE file
许可证
ase-swatch是MIT 许可的。
依赖项
~1.7–2.9MB
~48K SLoC