Created
April 6, 2011 17:51
-
-
Save JoshReedSchramm/906133 to your computer and use it in GitHub Desktop.
Prototyping turning an image into a masked cloud in RMagick
This file contains hidden or 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
This file contains hidden or 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
require "RMagick" | |
class CloudMasker | |
def initialize(destination) | |
@src = Magick::Image.new(190, 100) | |
@dst = Magick::Image.read(destination)[0] | |
@mask = Magick::Image.read(MASK_PATH)[0] | |
end | |
def make_cloud | |
@dst.resize_to_fill!(190, 100) | |
@dst = @dst.add_compose_mask(@mask) | |
@result = @dst.composite(@src, Magick::CenterGravity, Magick::OverCompositeOp) | |
@result = @result.add_compose_mask(@mask) | |
@result = @result.blur_image(0, 0.25) | |
@result.transparent("white").write(RESULT_PATH) | |
end | |
def self.make_image(destination) | |
File.delete(RESULT_PATH) if File.exist?(RESULT_PATH) | |
cm = CloudMasker.new(destination) | |
cm.make_cloud | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment