Class: GlyphImager::Imager
- Inherits:
-
Object
- Object
- GlyphImager::Imager
- Defined in:
- lib/glyph_imager.rb
Instance Method Summary collapse
- #command_string ⇒ Object
- #create_image ⇒ Object
-
#initialize(opts = {}) ⇒ Imager
constructor
A new instance of Imager.
- #label ⇒ Object
- #output_path ⇒ Object
- #pointsize ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Imager
Returns a new instance of Imager.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/glyph_imager.rb', line 79 def initialize(opts = {}) = { :size => "80x80", :pointsize_percentage => 100, :gravity => "center", :background => "none" }.merge(opts) %w[code_point font_path output_dir].each do |k| if [k.to_sym].nil? raise ArgumentError, "missing value for :#{k}" end end end |
Instance Method Details
#command_string ⇒ Object
112 113 114 |
# File 'lib/glyph_imager.rb', line 112 def command_string "convert -font #{@options[:font_path]} -background #{@options[:background]} -size #{@options[:size]} -gravity #{@options[:gravity]} -pointsize #{pointsize} #{label} #{output_path}" end |
#create_image ⇒ Object
116 117 118 119 |
# File 'lib/glyph_imager.rb', line 116 def create_image %x[#{command_string}] return self end |
#label ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/glyph_imager.rb', line 101 def label case [:code_point] when "0027" "label:\\#{[@options[:code_point].hex].pack("U*")}" when "005C" "label:'\\#{[@options[:code_point].hex].pack("U*")}'" else "label:'#{[@options[:code_point].hex].pack("U*")}'" end end |
#output_path ⇒ Object
93 94 95 |
# File 'lib/glyph_imager.rb', line 93 def output_path "#{@options[:output_dir]}/#{@options[:code_point]}-#{@options[:size]}.png" end |
#pointsize ⇒ Object
97 98 99 |
# File 'lib/glyph_imager.rb', line 97 def pointsize [:size].split("x").last.to_i * [:pointsize_percentage] / 100.0 end |