gd-icon-renderer
gd-icon-renderer
A (WIP) Crystal Geometry Dash icon renderer library, utilizing libvips
Why?
Server-side rendering of icons. This functionality doesn't need to be restricted to an HTTP server, so I figured I could just move it into a library.
Pre-requisites
You'll need to install libvips, alongside a devel
package for building if available. Be sure to leave this note in the README of the application you're making too.
Installation
-
Add the dependency to your
shard.yml
:dependencies: gd-icon-renderer: github: oatmealine/gd-icon-renderer
-
Run
shards install
Usage
Currently, for most examples under examples/
, you'll have to plug the icons
folder of your GD install in data/
. Otherwise, the process for rendering an icon is as follows:
-
Load spritesheets:
# Replace the filepaths here with whatever is relevant for your usecase sheet = IconRenderer::Assets.load_spritesheet("data/icons/ship_44-uhd.plist")
-
Render the icon out:
icon_img = IconRenderer::Renderer.render_icon("ship_44", [0.0, 0.0, 0.0, 1.0], [255/255, 125/255, 125/255, 1.0], nil, true, sheet)
You'll now be given a
Vips::Image
. -
(Optional) You might find it useful to now trim the whitespace out, as Geometry Dash icons usually have lots of surrounding blank space:
alpha = icon_img.extract_band(3) left, top, width, height = alpha.find_trim(threshold: 0, background: [0]) icon_img = icon_img.crop(left, top, width, height)
-
You'll most likely want to save the resulting image somewhere:
icon_img.write_to_file("icon_rendered.png")
gd-icon-renderer
- 1
- 0
- 2
- 1
- 1
- 11 months ago
- January 12, 2023
MIT License
Sun, 22 Dec 2024 04:25:38 GMT