0.0
No release in over 3 years
Imprint is a Ruby library for generating signed, time-limited image renders with dynamic text watermarks. It allows you to securely distribute images using expiring tokens, preventing unauthorized reuse or hotlinking. Imprint works as a pure Ruby library and can optionally integrate with Rails via an isolated engine. Image rendering is powered by the GD graphics library.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

 Project Readme

📖 Read the full article on Rubystack News: Imprint: Signed, Expiring Image Rendering with Dynamic Watermarks in Ruby

Imprint Image


Signed, expiring image watermark rendering for Ruby

imprint-image is a Ruby library for generating signed, time-limited image renders with dynamic text watermarks. It allows you to securely distribute images using expiring tokens, preventing unauthorized reuse, hotlinking, or permanent access.

The library is framework-agnostic and works as pure Ruby, with optional Rails integration.

Image rendering is powered by the GD graphics library.


Features

  • 🔐 Signed tokens with expiration
  • 🖼 Dynamic text watermarks rendered on the fly
  • ⏱ Time-limited image access
  • 🚫 Prevents hotlinking and unauthorized reuse
  • 🧩 Pure Ruby core
  • 🚆 Optional Rails integration (no forced dependency)

Installation

RubyGems

gem install imprint-image

or in your Gemfile:

gem 'imprint-image'

Requirements

  • Ruby ≥ 3.3
  • GD graphics library (libgd)
  • The ruby-libgd gem (installed automatically)

On Debian / Ubuntu:

sudo apt install libgd-dev

Basic Usage (Pure Ruby)

Generate a signed token

token = Imprint.sign(
  source: '/path/to/image.png',
  watermark: 'CONFIDENTIAL',
  expires_in: 60
)

Render an image from a token

output_path = Imprint.render_from_token(token)

if output_path
  puts "Rendered image at: #{output_path}"
else
  puts "Token expired or invalid"
end

Rails Integration (Optional)

Imprint does not force routes or controllers.

Example Route

get '/imprint/:token', to: 'imprint#show'

Example Controller

class ImprintController < ApplicationController
  def show
    path = Imprint.render_from_token(params[:token])
    return head :not_found unless path
    send_file path, type: 'image/png', disposition: 'inline'
  end
end

Example View

<img src="/imprint/<%= token.split('/').last %>" />

Rails View Helper

<%= imprint_image_tag(token, class: "watermarked") %>

Security Model

  • Tokens are signed and tamper-proof
  • Tokens include an expiration timestamp
  • Expired tokens cannot be rendered

Temporary Files

Rendered images are written to Dir.tmpdir. You are responsible for cleaning them if needed.


Development

bundle install
bundle exec rake

License

MIT License.


Author

Germán Giménez Silva
https://github.com/ggerman