Generating a barcode in a PDF for Rails with Prawnto and barcode-generator

For a project i needed to generate a barcode image in a PDF invoice. I was already using Prawnto to generate the PDF and needed a way to generate a barcode image to use with Prawnto.

After a few searches i found barcode-generator from anujluthra.

Install the gbarcode gem and ImageMagic.

if your are on OSX and get the following error: “sh: gs: command not found” then you don’t have postscript installed. Install Postscript trough Port. (port install postscript)

I found out that Prawnto really likes absolute file system paths instead of relative image tags that barcode-generator returns, so i forked the project on GitHub and added a new option to return the file system path instead of an image tag.

My fork can be found at: http://github.com/matsimitsu/barcode-generator/tree/master and can be installed as a plugin with:
script/install plugin git://github.com/matsimitsu/barcode-generator.git

To use this all in Prawnto use the following code:
pdf.image(barcode('FJJ4JD', :output_method => 'full_path'))

Filed Under: Ruby on Rails - read on

Een polaroid in Filecolumn met Magick (Ruby on Rails)

Voor een schoolopdracht (photoviewer) heb ik rails als backend gebruikt en omdat ik die mooie polaroid achtige afbeeldingen wilde hebben ben ik op zoek gegaan naar een oplossing in rails. Ik wist dat het mogelijk was met Rmagick, maar ik maakte ook al gebruik van FileColumn. Tijd om die twee te combineren.

Filecolumn had al de mogelijkheid om imagemagick aan te roepen door middel van dit soort code:

class Entry < ActiveRecord::Base
        file_column :image, :magick => { 
          :versions => { "thumb" => "50x50", "medium" => "640x480>"}
        }
end

Maar dit is niet genoeg, ik wil polaroids.

Filed Under: Code, Ruby on Rails - read on