lib/profound.rb in profound-0.0.4 vs lib/profound.rb in profound-0.0.5

- old
+ new

@@ -5,13 +5,11 @@ require 'tempfile' require 'profound/version' require 'profound/filters/toy_camera' -# convert original.jpg -size 460x -background transparent -fill black -pointsize 40 caption:'This is a multiline caption, This is a multiline caption, This is a multiline caption.' -gravity center -composite result.jpg - module Profound class Theme def initialize(theme) @theme = theme end @@ -103,20 +101,20 @@ end end def shadow image = _text(40) - shadow = image.shadow(0, 0, 30).colorize(1, 1, 1, 0, @theme.inverse_color) + shadow = image.shadow(0, 0, line_count(@caption) * 30).colorize(1, 1, 1, 0, @theme.inverse_color) @source = @source.composite(shadow, Magick::CenterGravity, 20, 0, Magick::OverCompositeOp) end def save @source.write(@destination) end def _text(stroke_width = 0) - image = Magick::Image.new(@source.columns, 100) { + image = Magick::Image.new(@source.columns, line_count(@caption) * 100) { self.background_color = 'none' } text = Magick::Draw.new color = @theme.color @@ -133,8 +131,12 @@ image rescue Magick::ImageMagickError => e puts "An error has occured. Try installing ghostscript" exit! + end + + def line_count(caption) + caption.split("\\n").count end end end