Generate PNG/JPEG directly from Ruby
Here's what this repo does. Shows immediate proof of creating standard image files without extra dependencies.
ggerman/ruby-libgd
Native Ruby bindings for the GD graphics library, providing fast image processing, drawing, filters, and alpha-blending without external dependencies.
THE USEFUL PART
Native Ruby bindings for the GD graphics library, providing fast image processing, drawing, filters, and alpha-blending without external dependencies.
THE STACKRADAR WALKTHROUGH
A short introduction from our reel. See the project README for the current details.
Here's what this repo does. Shows immediate proof of creating standard image files without extra dependencies.
This repo also lets you draw charts, dashboards, or custom graphics entirely in Ruby, avoiding separate chart libraries and keeping everything in one process for web.
This repo finally lets you produce GIS tiles and scientific plots server‐side, giving map services or data‐science apps fast, embeddable graphics without spawning extra processes.
GITHUB SNAPSHOT
Recorded counts, not a growth rate or a quality score.
OBSERVED STAR HISTORY
6 real daily observations. 105 → 105 stars.

FROM THE PROJECT
Source excerpts from the project's README. Not an independent review, verification or security audit.
Germán Alberto Giménez Silva | Remote
Create images with Ruby using the GD graphics library. This project demonstrates dynamic image generation in Ruby, allowing developers to programmatically create PNG and JPEG images.
# ruby-libgd is evolving very fast, so some examples may temporarily stop working
# Please report issues or ask for help — feedback is very welcome
# https://github.com/ggerman/ruby-libgd/issues or [email protected]
| Implemented | Implemented | Implemented |
|---|---|---|
Note: The images shown in Table 1, along with the code used to generate them, are available in the examples/ folder.
ruby-libgd is a modern native Ruby binding to the GD Graphics Library, providing Ruby with a fast, embeddable, server-side graphics engine.
It enables Ruby to generate images, charts, dashboards, GIS tiles, and scientific graphics without spawning external processes.
gem install ruby-libgd
System dependencies:
apt install -y libgd-dev pkg-config
ruby-libgd is a native extension and depends on libgd, which must be installed via Homebrew.
Install libgd
brew install gd
Verify Homebrew’s install path:
brew --prefix gd
Typical values: Apple Silicon (M1 / M2 / M3): /opt/homebrew
Intel Macs: /usr/local
Apple Silicon (M1 / M2 / M3)
Homebrew installs libraries into /opt/homebrew, which Ruby’s native extension builder does not detect automatically.
gem install ruby-libgd -- --with-gd-dir=/opt/homebrew
gem install ruby-libgd
🇬🇧 English: https://ggerman.github.io/ruby-libgd/en/
🇯🇵 日本語: https://ggerman.github.io/ruby-libgd/jp/
All runnable examples live in:
examples/ basics/ image_processing/ charts/ images/
Each Ruby script in examples/ generates an image in examples/images/.
GitHub: https://github.com/ggerman/ruby-libgd RubyGems: https://rubygems.org/gems/ruby-libgd Article: https://rubystacknews.com/2026/01/05/ruby-can-create-images-again/
ruby-libgd is developed and tested against libgd 2.3.3 using a reproducible Docker environment.
This ensures that the native extension is compiled against a known, stable GD ABI and behaves consistently across systems.
Reference Dockerfile
FROM ruby:3.3
RUN apt update && apt -y upgrade
RUN apt install -y \
libgd-dev \
libgd3 \
libgd-tools \
pkg-config \
ruby-dev \
build-essential \
valgrind
RUN printf "prefix=/usr\n\
exec_prefix=\${prefix}\n\
libdir=\${exec_prefix}/lib/x86_64-linux-gnu\n\
includedir=\${prefix}/include\n\
\n\
Name: gd\n\
Description: GD Graphics Library\n\
Version: 2.3\n\
Libs: -L\${libdir} -lgd\n\
Cflags: -I\${includedir}\n" \
> /usr/lib/x86_64-linux-gnu/pkgconfig/gd.pc
ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install
# Enforce dependency lockfile reproducibility
RUN bundle config --global frozen 1
COPY . .
ruby-libgd is a native C extension. The exact libgd version and build flags directly affect:
Alpha blending
Color accuracy
Filter behavior
Memory safety
Using a pinned, containerized build environment guarantees that:
The extension is compiled against libgd 2.3.x
pkg-config resolves the correct headers and linker flags
CI, contributors, and users see identical behavior
This is especially important for GIS, map tiles, and image pipelines where pixel-level consistency matters.
require "gd"
WIDTH = 800
HEIGHT = 400
img = GD::Image.new(WIDTH, HEIGHT)
# ----------------------------
# Pastel palette
# ----------------------------
bg_top = [244, 240, 255] # lavender
bg_bottom = [230, 248, 255] # light sky
accent1 = [255, 140, 180] # pastel pink
accent2 = [120, 200, 255] # pastel blue
text_main = [60, 70, 120] # deep indigo
shadow = [180, 190, 220]
# ----------------------------
# Soft gradient background
# ----------------------------
(0...HEIGHT).each do |y|
t = y.to_f / (HEIGHT - 1)
r = (bg_top[0] + (bg_bottom[0] - bg_top[0]) * t).to_i
g = (bg_top[1] + (bg_bottom[1] - bg_top[1]) * t).to_i
b = (bg_top[2] + (bg_bottom[2] - bg_top[2]) * t).to_i
img.line(0, y, WIDTH - 1, y, [r, g, b])
end
# ----------------------------
# Floating pastel blobs
# ----------------------------
img.filled_circle(120, 100, 80, accent2)
img.filled_circle(680, 280, 100, accent1)
img.filled_circle(700, 80, 50, [200, 230, 255])
# ----------------------------
# Text
# ----------------------------
font = "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"
title_size = 52
subtitle_size = 20
title = "RubyStackNews"
subtitle = "The pulse of the Ruby ecosystem"
# Manual centering
title_x = 80
title_y = 190
# Soft shadow
img.text(title, {
x: title_x + 2,
y: title_y + 2,
size: title_size,
color: shadow,
font: font
})
# Main title
img.text(title, {
x: title_x,
y: title_y,
size: title_size,
color: text_main,
font: font
})
# Subtitle
img.text(subtitle, {
x: title_x,
y: title_y + 45,
size: subtitle_size,
color: [100,110,160],
font: font
})
# ----------------------------
# Call-to-action pill
# ----------------------------
pill_x = 80
pill_y = 260
pill_w = 260
pill_h = 44
img.filled_rectangle(pill_x, pill_y, pill_x + pill_w, pill_y + pill_h, [255,255,255])
img.rectangle(pill_x, pill_y, pill_x + pill_w, pill_y + pill_h, accent2, thickness: 2)
img.text("rubystacknews.com", {
x: pill_x + 22,
y: pill_y + 30,
size: 20,
color: text_main,
font: font
})
# ----------------------------
# Save
MIT License. Copyright (c) 2025 Germán Alberto Giménez Silva.
Read the original READMEKEEP EXPLORING
Repository preview
strelov1/freehire
Open-source search engine aggregating 3.3M+ tech jobs directly from 294k+ company career pages. Zero recruiters, no reposts.
git clone https://github.com/strelov1/freehire.gitzenhostai/9drive
Virtual storage gateway pooling multiple free Google Drive accounts into a combined 60GB+ high-speed personal bucket.
git clone https://github.com/zenhostai/9drive.gitNatively-AI-assistant/natively-cluely-ai-assistant
Natively — Free open-source AI meeting assistant, interview copilot, and note taker. The best alternative to Cluely, Otter, Granola, Final Round AI, Fireflies, and Interview Coder. Real-time transcription, AI meeting notes, lecture recording, local RAG, BYOK, and stealth mode. Runs locally. No subscriptions. No data breaches.
git clone https://github.com/Natively-AI-assistant/natively-cluely-ai-assistant.gitShort demos. New discoveries. Less noise in your feed.