Last active
December 10, 2015 13:18
-
-
Save pbartunek/4440308 to your computer and use it in GitHub Desktop.
Annotate images with paperclip.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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