OpenRaster layered document editing and compositing in MoonBit
git clone https://github.com/gywcs101/MoonOpenRaster.git
cd MoonOpenRaster
moon update
python scripts/serve_web.pymoon add gywcs101/MoonOpenRaster@0.2.0import {
"gywcs101/MoonOpenRaster" @ora,
}fn main raise {
let image = @ora.Image::new(1, 1, [255, 0, 0, 255])
let layer = @ora.Node::Layer(@ora.Properties::new("红色图层"), image)
let document = @ora.Document::new(4, 4, [layer])
let edited = document.set_properties(
[0],
@ora.Properties::new("移动后的图层", x=1, y=1),
)
let archive = edited.write()
let reopened = @ora.read(archive)
let png = reopened.render().encode_png()
println(png.length())
}moon run cmd/main --target js -- inspect drawing.ora
moon run cmd/main --target js -- render drawing.ora composite.png
moon run cmd/main --target js -- edit drawing.ora changed.ora edits.json[{"path":[0,0],"name":"移动后的图层","x":20,"y":10,"visible":true,"opacity":0.5,"composite_op":"svg:src-over"}]python scripts/check_rgba16.pypub(all) suberror OraError {
InvalidDocument(String)
Unsupported(String)
}pub struct Document {
width : Int
height : Int
name : String
// private fields
}fn Document::set_properties(self : Document, path : Array[Int], properties : Properties) -> Document raisepub struct Image {
width : Int
height : Int
// private fields
}pub struct Properties {
name : String
x : Int
y : Int
visible : Bool
opacity : Double
composite_op : String
// private fields
}fn Properties::new(name : String, x? : Int, y? : Int, visible? : Bool, opacity? : Double, composite_op? : String) -> Properties raise OraErrorfn validate_preview(data : Bytes, width : Int, height : Int) -> Unit raise