ProgressbarSnapshot

A simple widget that generates progress bars in png format. There are other ways to generate a progress bar with css, html and javascript. However, if you have to stick a progress bar in a pdf you probably need to stick it in as an image.

Requires the Rmagick library

Example usage:

In a stand alone script:

require 'progress_bar_snapshot'

pb = ProgressBarSnapshot.new(200, 50, 85.0)
pb.to_file("85percent.png")

This will generate a png file 200x50 called 85percent.png. The progress bar would be 85% full.

In your rails app:

In your controller:
  require 'progress_bar_snapshot'
  ...
  class MySomethingController < ApplicationController
     helper :progress_bar_snapshot
  ...
  # define an action to render and send the png
  def progress_bar
    bar = ProgressBarSnapshot.new(
      params[:width].to_i, params[:height].to_i, 
      params[:percentage].to_f)

    send_data bar.to_blob, :type => 'image/png', :disposition => 'inline', 
                           :filename => "progress#{params[:percentage].to_i}.png"
  end

In your view:
   <%= progress_bar_png_tag('88.1', {
     :width => 200, :height=> 20, :controller => 'my_something', :action => 'progress_bar'}) %>

Customizable colors:

These following parameters can be passed in to the progress bar snapshot constructor

:inner_border   # inner border of the progress bar default to "#CCCCCC",
:border_color   # outer border color defaults to "#666666", 
:progress_color # progress bar color defaults to "#B3D235",
:background     # color of unfilled portion of the progress bar, defaults to "white",
:font_family    # default font to "arial",
:font_color     # default color of the font "black",

All the colors are passed straight to Rmagick, so they can be any color Rmagick supports.

For example:

pb = ProgressBarSnapshot.new(200, 50, 35.1, :border_color => ‘black’,

:progress_color => 'green', :font_color => 'white', :background => 'grey')

Authors, credits, blame, contact!

xiaoke@microplace.com
julio@microplace.com