Crystal bindings to Blend2D.
-
Install Blend2D
-
Add the dependency to your
shard.yml
:dependencies: blend2d: github: aramvisser/blend2d.cr
-
Run
shards install
This will generate a black circle on a transparent background
require "blend2d"
# Create a new image and setup the rendering context
img = Blend2D::Image.new 480, 480
ctx = Blend2D::Context.new img
# Make the background transparent
ctx.clear_all
# Set the current fill style to black
ctx.comp_op = :src_over
ctx.fill_style = Blend2D::RGBA32.new(0, 0, 0)
# Fill a circle using the current fill style
ctx.fill_circle cx: 240, cy: 240, r: 200
ctx.end
img.write_to_file "example.png"
See the examples
directory for more examples.
For usage of Blend2D itself, see the Blend2D Documentation itself.
This binding wraps the Blend2D C Api, but tries to follow the Blend2D C++ api design.
- Core classes are available in the Blend2D namespace, e.g.
BLContextCore
isBlend2D::Context
. - Enums are abbreviated and made camelcase, e.g.
COMP_OP_SRC_OVER
isBlend2D::CompOp::SrcOver
.
It also does things differently to make them more crystal like.
- Methods that return a
BLResult
in the C Api either throw an exception on error. - Getter and setter methods that start with
get
andset
act like accessors, i.e.Context#fill_style=
orContext#comp_op
.
The bindings are split into different modules that are also used in the Blend2D
docs, like Imaging, Rendering, etc. This is only done to make things more
organized. All modules are included directly in the Blend2D
namespace. The
different submodules are not needed during usage.
Crystal methods were automatically generated from all C api's. They are defined
in the src/blend2d/generated
directory. Those methods have long names based on the C
call, they are not documented and should only be used as a backup.
These methods work like a todo-list. They should be cleaned up and moved into the main class eventually.
The C bindings in src/blend2d/lib_blend2d/
are automatically generated. Run support/generate_bindings.cr
with the path to the blend2d.h
file to regenerate the bindings:
crystal run support/generate_bindings.cr -- path/to/blend2d/src/blend2d.h
- Fork it (https://github.com/your-github-user/blend2d.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- Aram Visser - creator and maintainer
- Voximity - original Blend2D bindings