Skip to content

Instantly share code, notes, and snippets.

@pbartunek
Last active December 10, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pbartunek/4440308 to your computer and use it in GitHub Desktop.
Save pbartunek/4440308 to your computer and use it in GitHub Desktop.
Annotate images with paperclip.
module Paperclip
class Annotation < Thumbnail
attr_accessor :annotation_text
def initialize(file, options = {}, attachment = nil)
super
@geometry = options[:geometry]
@annotation_text = options[:annotation_text]
@annotation_font_size = (options[:annotation_font_size] or 18)
@annotation_position = (options[:annotation_position] or 'SouthEast')
end
def transformation_command
trans = []
if not @annotation_text.nil? and not @annotation_text.empty?
trans << "-gravity #{@annotation_position}"
trans << "-pointsize #{@annotation_font_size}"
trans << "-stroke '#000C' -strokewidth 2 -annotate 0 '#{@annotation_text}'"
trans << "-stroke none -fill white -annotate 0 '#{@annotation_text}'"
end
super + trans
end
end
end
class Photo < ActiveRecord::Base
attr_accessible :image
belongs_to :post
has_attached_file :image,
:processors => [:annotation],
:styles => {
:thumb => '160x120',
:medium => '300x300',
:large => {
:geometry => '700x700',
:annotation_text => 'annotation text',
},
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment