ruby-libgd

Create Images with Ruby

ruby-libgd lets developers create images with Ruby using the native GD Graphics Library. It enables dynamic image generation in Ruby for PNG and JPEG images, charts, maps, dashboards, and server-side rendering without ImageMagick or external processes.

GitHub RubyGems Read the story

Connect

Documentation

Create Images with Ruby Using ruby-libgd

ruby-libgd is a native Ruby graphics library designed to create images with Ruby. It provides fast, reliable, and fully in-process Ruby image generation using the GD raster engine.

If you are searching for a way to:

ruby-libgd is built specifically for dynamic image generation in Ruby applications.

Examples of Images Created with Ruby

Pie chart created with Ruby using ruby-libgd

Why Use ruby-libgd for Ruby Image Generation?

Ruby lost its native graphics layer. ImageMagick is slow, fragile, and unsuitable for server-side image generation in Ruby.

ruby-libgd restores the ability to create images with Ruby using a true raster engine: no shelling out, no background daemons, and full pixel-level control directly from Ruby code.

Install

gem install ruby-libgd
apt install -y libgd-dev pkg-config

How to Create Images with Ruby

Creating images with Ruby using ruby-libgd is simple and fast. The library allows Ruby applications to generate images dynamically without spawning external processes.


require "gd"

img = GD::Image.new(400,400)

blue  = GD::Color.rgb(0,120,255)
green = GD::Color.rgb(0,200,120)

img.line(50,50,350,350, blue)
img.rectangle(50,50,350,350, blue)
img.filled_circle(200,200,80, green)

poly = [
  [200,50],
  [350,200],
  [200,350],
  [50,200]
]
img.filled_polygon(poly, GD::Color.rgb(240,200,0))

img.save("shapes.png")
  

This example demonstrates how to create images with Ruby and export them as PNG files.

Example Render

Frequently Asked Questions

Can Ruby create images?

Yes. Ruby can create images using ruby-libgd, which provides native image generation for PNG and JPEG files.

Is ruby-libgd an alternative to ImageMagick?

Yes. ruby-libgd is a lightweight, native alternative for creating images with Ruby without external dependencies.