lib/profound.rb in profound-0.0.1 vs lib/profound.rb in profound-0.0.2
- old
+ new
@@ -1,7 +1,7 @@
-require "profound/version"
-require 'choice'
+require 'profound/version'
+require 'profound/filters/toy_camera'
require 'rmagick'
module Profound
class Theme
def initialize(theme)
@@ -16,56 +16,64 @@
@theme == :dark ? 'white' : 'black'
end
end
class Image
+ include Profound::Filters::ToyCamera
+
def initialize(source, caption, options, destination)
- @image_list = Magick::ImageList.new(source)
- @source = @image_list.first
- # @image_list = Magick::ImageList.new
+ @source = Magick::ImageList.new(source).first
@target = Magick::ImageList.new
@destination = destination
@caption = caption
@options = options
@theme = Theme.new(options[:theme])
end
def convert
- shadow!
- text!
- save!
+ shadow
+ text
+ filters
+ save
end
- def text!
- @source = @source.composite(text, Magick::CenterGravity, Magick::OverCompositeOp)
+ def text
+ @source = @source.composite(_text, Magick::CenterGravity, Magick::OverCompositeOp)
end
- def text(color = nil, stroke_width = 0)
+ def filters
+ case @options[:filter]
+ when :toycamera
+ toy_camera
+ end
+ end
+
+ def shadow
+ image = _text(40)
+ shadow = image.shadow(0, 0, 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) {
self.background_color = 'none'
}
text = Magick::Draw.new
- color ||= @theme.color
+ color = @theme.color
text.annotate(image, 0, 0, 0, 0, @caption) {
self.fill = color
self.font_family = 'Arial'
self.pointsize = 80
self.stroke_width = stroke_width
self.stroke = color
self.gravity = Magick::CenterGravity
}
image
- end
-
- def shadow!
- image = text(@theme.inverse_color, 40)
- @source = @source.composite(image.shadow(0, 0, 30), Magick::CenterGravity, 20, 0, Magick::OverCompositeOp)
- end
-
- def save!
- # img = @image_list.flatten_images
- @source.write(@destination)
end
end
end